std::bernoulli_distribution
提供: cppreference.com
ヘッダ <random> で定義 | ||
class bernoulli_distribution; | (C++11以上) | |
離散確率関数に従ってランダムなブーリアン値を生成します。 true の確率は以下の通りです。
- P(b|p) =⎧
⎨
⎩p if b ==true
1 − p if b ==false
std::bernoulli_distribution
は RandomNumberDistribution を満たします。
目次 |
[編集]メンバ型
メンバ型 | 定義 |
result_type | bool |
param_type | パラメータセットの型、 RandomNumberDistribution を参照してください |
[編集]メンバ関数
新しい分布を構築します (パブリックメンバ関数) | |
分布の内部状態をリセットします (パブリックメンバ関数) | |
生成 | |
分布の次の乱数を生成します (パブリックメンバ関数) | |
特性 | |
分布のパラメータ p (true を生成する確率) を返します (パブリックメンバ関数) | |
分布のパラメータオブジェクトを取得または設定します (パブリックメンバ関数) | |
生成される可能性のある最小値を返します (パブリックメンバ関数) | |
生成される可能性のある最大値を返します (パブリックメンバ関数) |
[編集]非メンバ関数
2つの分布オブジェクトを比較します (関数) | |
乱数分布に対してストリーム入出力を行います (関数テンプレート) |
[編集]例
Run this code
#include <iostream>#include <iomanip>#include <string>#include <map>#include <random> int main(){std::random_device rd;std::mt19937 gen(rd());// give "true" 1/4 of the time// give "false" 3/4 of the time std::bernoulli_distribution d(0.25); std::map<bool, int> hist;for(int n=0; n<10000;++n){++hist[d(gen)];}for(auto p : hist){std::cout<<std::boolalpha<<std::setw(5)<< p.first<<' '<<std::string(p.second/500, '*')<<'\n';}}
出力例:
false *************** true ****
[編集]外部リンク
Weisstein, Eric W. "Bernoulli Distribution." From MathWorld--A Wolfram Web Resource.