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

1 つ目のコンストラクターは、格納されている値 stored_p に値 p0 を保持するオブジェクトを作成します。

2 つ目のコンストラクターは、格納されているパラメーターが 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

参照

関連項目

<random>

bernoulli_distribution クラス