bernoulli_distribution::bernoulli_distribution
建構散發。
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