std::exponential_distribution
From cppreference.com
| ヘッダー <random> で定義 |
||
| template< class RealType = double > class exponential_distribution; |
(C++11以降) | |
確率密度関数に従って、非負の浮動小数点値 x を生成します。
- P(x|λ) = λe-λx
得られる値は、単位時間または単位距離あたり一定のレート λ でランダムなイベントが発生する場合の、次のランダムイベントまでの時間/距離です。例えば、この分布はガイガーカウンターのクリック間隔や、DNA鎖の点突然変異間の距離を表します。
これは std::geometric_distribution の連続版です。
std::exponential_distribution は RandomNumberDistribution を満たします。
目次 |
[編集] テンプレートパラメータ
| RealType | - | ジェネレータによって生成される結果の型。これが float, double, または long double のいずれでもない場合、動作は未定義です。 |
[編集] メンバ型
| メンバ型 | 定義 |
result_type (C++11) |
RealType |
param_type (C++11) |
パラメータセットの型。RandomNumberDistribution を参照してください。 |
[編集] メンバ関数
| (C++11) |
新しい分布を構築します。 (public member function) |
| (C++11) |
分布の内部状態をリセットします。 (public member function) |
生成 | |
| (C++11) |
分布における次の乱数を生成する (public member function) |
特性 | |
| (C++11) |
lambda 分布パラメータ(イベントレート)を返します。 (public member function) |
| (C++11) |
分布パラメータオブジェクトを取得または設定します。 (public member function) |
| (C++11) |
生成される可能性のある最小値を返します。 (public member function) |
| (C++11) |
生成される可能性のある最大値を返します。 (public member function) |
[編集] 非メンバ関数
| (C++11)(C++11)(C++20で削除) |
2つの分布オブジェクトを比較します。 (function) |
| (C++11) |
疑似乱数分布のストリーム入出力を実行 (関数テンプレート) |
[編集] 注記
RealType が float の場合、実装によってはまれに無限大を返すことがあります。これは LWG issue 2524 です。
[編集] 例
このコードを実行
#include <iomanip> #include <iostream> #include <map> #include <random> #include <string> int main() { std::random_device rd; std::mt19937 gen(rd()); // if particles decay once per second on average, // how much time, in seconds, until the next one? std::exponential_distribution<> d(1); std::map<int, int> hist; for (int n = 0; n != 10000; ++n) ++hist[2 * d(gen)]; for (auto const& [x, y] : hist) std::cout << std::fixed << std::setprecision(1) << x / 2.0 << '-' << (x + 1) / 2.0 << ' ' << std::string(y / 200, '*') << '\n'; }
実行結果の例
0.0-0.5 ******************* 0.5-1.0 *********** 1.0-1.5 ******* 1.5-2.0 **** 2.0-2.5 ** 2.5-3.0 * 3.0-3.5 3.5-4.0
[編集] 外部リンク
| Weisstein, Eric W. "Exponential Distribution." From MathWorld — A Wolfram Web Resource. |