std::discrete_distribution
STD::离散[医]分布
Defined in header | | |
---|---|---|
template< class IntType = int > class discrete_distribution; | | (since C++11) |
std::discrete_distribution
生成区间上的随机整数。[0, n)
,其中每个整数的概率i
定义为w
I/S,这是重量
在...i
第四整数除以所有整数的和n
举重。
std::discrete_distribution
满足…的所有要求RandomNumberDistribution
...
模板参数
IntType | - | The result type generated by the generator. The effect is undefined if this is not one of short, int, long, long long, unsigned short, unsigned int, unsigned long, or unsigned long long. |
---|
成员类型
Member type | Definition |
---|---|
result_type | IntType |
param_type | the type of the parameter set, see RandomNumberDistribution. |
成员函数
(constructor) | constructs new distribution (public member function) |
---|---|
reset | resets the internal state of the distribution (public member function) |
世代
运算符%28%29在分布%28公共成员函数%29中生成下一个随机数。
特征
概率获得概率列表%28公共成员函数%29
Param获取或设置分布参数对象%28公共成员函数%29
min返回最小潜在生成值%28公共成员函数%29
MAX返回最大潜在生成值%28公共成员函数%29
非会员职能
operator==operator!= | compares two distribution objects (function) |
---|---|
operator<<operator>> | performs stream input and output on pseudo-random number distribution (function template) |
例
二次
#include <iostream>
#include <map>
#include <random>
int main()
{
std::random_device rd;
std::mt19937 gen(rd()
std::discrete_distribution<> d{40, 10, 10, 40}
std::map<int, int> m;
for(int n=0; n<10000; ++n) {
++m[d(gen)];
}
for(auto p : m) {
std::cout << p.first << " generated " << p.second << " times\n";
}
}
二次
产出:
二次
0 generated 4028 times
1 generated 978 times
2 generated 1012 times
3 generated 3982 times
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。