构造分发点对应。
bernoulli_distribution(double p0 = 0.5);
explicit bernoulli_distribution(const param_type& par0);
参数
p0
p分发参数。par0
使用的参数包构造分布。
备注
前置条件: 0.0 ≤ p0 && p0 ≤ 1.0
第一个构造函数构造存储值 stored_p 包含该值 p0的对象。
第二个构造函数构造存储参数从 par0初始化的对象。
示例
// std_tr1__random__bernoulli_distribution_construct.cpp
// compile with: /EHsc
#include <random>
#include <iostream>
typedef std::mt19937 Myeng;
typedef std::bernoulli_distribution Mydist;
int main()
{
Myeng eng;
Mydist dist(0.6);
Mydist::input_type engval = eng();
Mydist::result_type distval = dist(eng);
distval = distval; // to quiet "unused" warnings
engval = engval;
std::cout << "p == " << dist.p() << std::endl;
dist.reset(); // discard any cached values
std::cout << "a random value == " << std::boolalpha
<< dist(eng) << std::endl;
std::cout << "a random value == " << std::boolalpha
<< dist(eng) << std::endl;
std::cout << "a random value == " << std::boolalpha
<< dist(eng) << std::endl;
return (0);
}
要求
标头: <random>
命名空间: std