名前空間
変種
操作

std::binomial_distribution

提供: cppreference.com
< cpp‎ | numeric‎ | random
 
 
 
擬似乱数生成
一様ランダムビットジェネレータ
エンジンとエンジンアダプタ
非決定的なジェネレータ
分布
一様分布
ベルヌーイ分布
binomial_distribution
(C++11)
ポアソン分布
正規分布
標本分布
シードシーケンス
(C++11)
C のライブラリ
 
 
ヘッダ <random> で定義
template< class IntType = int >
class binomial_distribution;
(C++11以上)

以下の離散確率関数に従って分布する、ランダムな非負の整数値 i を生成します。

P(i|t,p) =

t
i


· pi
· (1 − p)t−i

取得される値は、各々が p の確率で成功する成功/失敗の t 回の試行のシーケンスにお���る、成功の数です。

std::binomial_distributionRandomNumberDistribution を満たします。

目次

[編集] テンプレート引数

IntType - ジェネレータが生成する結果の型。 shortintlonglong longunsigned shortunsigned intunsigned long または unsigned long long のいずれかでない場合、効果は未定義です


[編集] メンバ型

メンバ型 定義
result_type IntType
param_type パラメータセットの型、 RandomNumberDistribution を参照してください

[編集] メンバ関数

新しい分布を構築します
(パブリックメンバ関数) [edit]
分布の内部状態をリセットします
(パブリックメンバ関数) [edit]
生成
分布の次の乱数を生成します
(パブリックメンバ関数) [edit]
特性
分布のパラメータを返します
(パブリックメンバ関数) [edit]
分布のパラメータオブジェクトを取得または設定します
(パブリックメンバ関数) [edit]
生成される可能性のある最小値を返します
(パブリックメンバ関数) [edit]
生成される可能性のある最大値を返します
(パブリックメンバ関数) [edit]

[編集] 非メンバ関数

2つの分布オブジェクトを比較します
(関数) [edit]
乱数分布に対してストリーム入出力を行います
(関数テンプレート) [edit]

[編集]

パスカルの三角形との関連性を示す、各試行の成功率がちょうど50%である二項分布のプロット (この場合、4回の試行のうち成功する回数が 0, 1, 2, 3, 4 である確率は 1:4:6:4:1 です)。

#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
 
int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    // perform 4 trials, each succeeds 1 in 2 times
    std::binomial_distribution<> d(4, 0.5);
 
    std::map<int, int> hist;
    for (int n = 0; n < 10000; ++n) {
        ++hist[d(gen)];
    }
    for (auto p : hist) {
        std::cout << p.first << ' '
                  << std::string(p.second/100, '*') << '\n';
    }
}

出力例:

0 ******
1 ************************
2 *************************************
3 *************************
4 ******

[編集] 外部リンク

Weisstein, Eric W. "Binomial Distribution." From MathWorld--A Wolfram Web Resource.