Namespaces
Variants

std:: poisson_distribution

From cppreference.net
定義先ヘッダ <random>
template < class IntType = int >
class poisson_distribution ;
(C++11以降)

ランダムな非負整数値 i を生成し、離散確率関数に従って分布させます:

P(i|μ) =
e
·μ i
i!

得られる値は、正確に i 回のランダム事象が発生する確率であり、同じ条件下(同じ時間/空間区間)での期待される 平均 発生回数が μ である場合の値です。

std::poisson_distribution RandomNumberDistribution を満たす。

目次

テンプレートパラメータ

IntType - ジェネレータによって生成される結果の型。これが short int long long long unsigned short unsigned int unsigned long 、または unsigned long long のいずれでもない場合、動作は未定義です。

メンバー型

メンバー型 定義
result_type (C++11) IntType
param_type (C++11) パラメータセットの型。 RandomNumberDistribution を参照。

メンバー関数

新しい分布を構築する
(public member function)
(C++11)
分布の内部状態をリセットする
(public member function)
生成
(C++11)
分布における次の乱数を生成する
(public member function)
特性
(C++11)
mean 分布パラメータ(事象の平均発生回数)を返す
(public member function)
(C++11)
分布パラメータオブジェクトを取得または設定する
(public member function)
(C++11)
生成され得る最小値を返す
(public member function)
(C++11)
生成され得る最大値を返す
(public member function)

非メンバー関数

(C++11) (C++11) (C++20で削除)
二つの分布オブジェクトを比較する
(関数)
擬似乱数分布に対するストリーム入出力を実行する
(関数テンプレート)

#include <iomanip>
#include <iostream>
#include <map>
#include <random>
#include <string>
int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    // 平均して1分間に4回発生する事象が、1分間にn回発生する頻度は?
    std::poisson_distribution<> d(4);
    std::map<int, int> hist;
    for (int n = 0; n != 10000; ++n)
        ++hist[d(gen)];
    for (auto [x, y] : hist)
        std::cout << std::hex << x << ' '
                  << std::string(y / 100, '*') << '\n';
}

出力例:

0 *
1 *******
2 **************
3 *******************
4 *******************
5 ***************
6 **********
7 *****
8 **
9 *
a
b
c
d

外部リンク

Weisstein, Eric W. "Poisson Distribution." From MathWorld — A Wolfram Web Resource.
Weisstein, Eric W. "ポアソン分布" MathWorld — Wolfram Webリソースより