std::weibull_distribution

出自cppreference.com
 
 
 
 
 
在標頭 <random> 定義
template< class RealType = double >
class weibull_distribution;
(C++11 起)

weibull_distribution 滿足隨機數分布 (RandomNumberDistribution) 的要求並產生服從威布爾分布的隨機數。

{{mathjax-or|1=\(\small{f(x;a,b)=\frac{a}{b}{(\frac{x}{b})}^{a-1}\exp{(-{(\frac{x}{b})}^{a})} }\)|2=f(x;a,b) =
a
b


x
b


a-1
exp

-

x
b


a


}}

a形狀參數b尺度參數

模板形參

RealType - 生成器所生成的結果類型。如果它不是 floatdoublelong double 之一,那麼效果未定義。

成員類型

成員類型 定義
result_type (C++11) RealType
param_type(C++11) 參數集的類型,見隨機數分布 (RandomNumberDistribution)

成員函數

構造新分布
(公開成員函數) [編輯]
(C++11)
重置分布的內部狀態
(公開成員函數) [編輯]
生成
生成分布中的下個隨機數
(公開成員函數) [編輯]
特徵
(C++11)
返回分布參數
(公開成員函數) [編輯]
(C++11)
獲取或設置隨機參數對象
(公開成員函數) [編輯]
(C++11)
返回潛在生成的最小值
(公開成員函數) [編輯]
(C++11)
返回潛在生成的最大值
(公開成員函數) [編輯]

非成員函數

(C++11)(C++11)(C++20 移除)
比較兩個分布對象
(函數) [編輯]
���行偽隨機數分布的流輸入和輸出
(函數模板) [編輯]

示例

#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>

int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
 
    std::weibull_distribution<> d;
 
    std::map<int, int> hist;
    for (int n = 0; n != 10000; ++n)
        ++hist[std::round(d(gen))];

    std::cout << std::fixed << std::setprecision(1) << std::hex;
    for (auto [x, y] : hist)
        std::cout << x << ' ' << std::string(y / 200, '*') << '\n';
}

可能的輸出:

0 *******************
1 *******************
2 ******
3 **
4
5
6
7
8

外部鏈接

1.  Weisstein, Eric W. 「威布爾分布」 來自 MathWorld — A Wolfram Web Resource。
2.  威布爾分布 — 來自 Wikipedia。