std:: negative_binomial_distribution
From cppreference.net
|
ヘッダーで定義
<random>
|
||
|
template
<
class
IntType
=
int
>
class negative_binomial_distribution ; |
(C++11以降) | |
ランダムな非負整数値 i を生成し、離散確率関数に従って分布させます:
-
P(i|k,p) =
⎛
⎜
⎝ k + i − 1
i ⎞
⎟
⎠ · p k
· (1 − p) i
この値は、独立した成功/失敗の試行(各試行が確率 p で成功する)において、正確に k 回の成功が発生するまでの失敗回数を表します。
std::negative_binomial_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 を参照。 |
メンバー関数
|
(C++11)
|
新しい分布を構築する
(public member function) |
|
(C++11)
|
分布の内部状態をリセットする
(public member function) |
生成 |
|
|
(C++11)
|
分布内の次の乱数を生成する
(public member function) |
特性 |
|
|
(C++11)
|
分布パラメータを返す
(public member function) |
|
(C++11)
|
分布パラメータオブジェクトを取得または設定する
(public member function) |
|
(C++11)
|
生成されうる最小値を返す
(public member function) |
|
(C++11)
|
生成されうる最大値を返す
(public member function) |
非メンバー関数
|
(C++11)
(C++11)
(removed in C++20)
|
二つの分布オブジェクトを比較する
(関数) |
|
(C++11)
|
擬似乱数分布に対するストリーム入出力を実行する
(関数テンプレート) |
例
このコードを実行
#include <iomanip> #include <iostream> #include <map> #include <random> #include <string> int main() { std::random_device rd; std::mt19937 gen(rd()); // パットはクッキーを販売するために戸別訪問する // 各家で、75%の確率で1箱販売できる // 5箱販売する前に何回断られるだろうか? std::negative_binomial_distribution<> d(5, 0.75); 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
外部リンク
| Weisstein, Eric W. "負の二項分布。" MathWorld — Wolfram Web リソースより。 |