std::weibull_distribution
来自 zh.cppreference.net
| 定义于头文件 <random>
|
||
template< class RealType = double >
class weibull_distribution;
|
(C++11 起) | |
std::weibull_distributionweibull_distribution 满足 RandomNumberDistribution 的要求,并根据 韦伯分布 (Weibull distribution) 生成随机数:
- f(x;a,b) =
· ⎛a b
⎜
⎝
⎞x b
⎟
⎠a-1
· exp⎛
⎜
⎝-⎛
⎜
⎝
⎞x b
⎟
⎠a
⎞
⎟
⎠
std::weibull_distribution 满足 RandomNumberDistribution。
模板参数
| RealType | - | 生成器产生的结果类型。若该类型不是 float 、 double 或 long 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++11)
(C++11)
(removed in C++20)
|
比较两个分布对象
(函数) |
|
(C++11)
|
对伪随机数分布执行流输入和输出操作
(函数模板) |
示例
运行此代码
#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. "Weibull Distribution." 来自 MathWorld —— 一个 Wolfram 网络资源。 |
| 2. | Weibull distribution —— 来自维基百科。 |