- random[meta header]
- std[meta namespace]
- class template[meta id-type]
- cpp11[meta cpp]
namespace std {
template <class IntType = int>
class binomial_distribution;
}
binomial_distribution
は、離散確率分布の一種である二項分布を表すクラスである。
成功する確率pの事象をn回試行し、成功した回数を求める。
二項分布は、以下のような用途に使用できる:
- 死亡する確率があるワクチンをN人に投与し、生き残る(or 死亡する)人数を求める
- N個の製品に、確率pで不良品が発生する
テンプレートパラメータは、以下を意味する:
名前 |
説明 |
対応バージョン |
(constructor) |
コンストラクタ |
C++11 |
~binomial_distribution() = default; |
デストラクタ |
C++11 |
reset |
状態をリセットする |
C++11 |
名前 |
説明 |
対応バージョン |
t |
試行回数を取得する |
C++11 |
p |
確率を取得する |
C++11 |
param |
分布のパラメータを取得/設定する |
C++11 |
min |
生成し得る値の下限を取得する |
C++11 |
max |
生成し得る値の上限を取得する |
C++11 |
型 |
説明 |
対応バージョン |
result_type |
乱数生成結果の整数型。IntType |
C++11 |
param_type |
分布パラメータの型。未規定。 |
C++11 |
#include <iostream>
#include <random>
int main()
{
std::random_device seed_gen;
std::default_random_engine engine(seed_gen());
// 成功確率0.5の事象を5回試行する
std::binomial_distribution<> dist(5, 0.5);
// 成功した回数を取得(0以上5以下の値が返される)
int result = dist(engine);
std::cout << result << std::endl;
}
- std::binomial_distribution[color ff0000]
- dist(engine)[link binomial_distribution/op_call.md]