std::negative_binomial_distribution
性病:否定[医]二项式[医]分布
Defined in header | | |
---|---|---|
template< class IntType = int > class negative_binomial_distribution; | | (since C++11) |
产生随机非负整数值i,按离散概率函数分布:p%28 i k,p%29=。
二次
二次
k+I-1
我...
二次
·PK
·%281-p%29I
该值表示一系列独立的“是/否”试验中失败的次数%28,每个试验成功的概率为p%29,在完全k次成功之前。
std::negative_binomial_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中生成下一个随机数。
特征
pk返回分布参数%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 <iomanip>
#include <string>
#include <map>
#include <random>
int main()
{
std::random_device rd;
std::mt19937 gen(rd()
// Pat goes door-to-door selling cookies
// At each house, there's a 75% chance that she sells one box
// how many times will she be turned away before selling 5 boxes?
std::negative_binomial_distribution<> d(5, 0.75
std::map<int, int> hist;
for(int n=0; n<10000; ++n) {
++hist[d(gen)];
}
for(auto p : hist) {
std::cout << p.first << ' ' << std::string(p.second/100, '*') << '\n';
}
}
二次
产出:
二次
0 ***********************
1 *****************************
2 **********************
3 *************
4 ******
5 ***
6 *
7
8
9
10
11
二次
外部链接
负二项分布。来自MathWorld的一个Wolfram Web资源。
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。