名前空間
変種
操作

std::exponential_distribution

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

以下の確率密度関数に従って分布する、ランダムな非負の浮動小数点値 x を生成します。

P(x|λ) = λe-λx

取得される値は、単位時間/距離あたり λ の割合でランダムな事象が発生する場合の、次にその事象が発生するまでの時間/距離です。 例えば、この分布はガイガーカウンターの音が鳴る間隔、あるいは DNA の螺旋構造の点変異間の距離などを表します。

これは std::geometric_distribution の連続版です。

std::exponential_distributionRandomNumberDistribution を満たします。

目次

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

RealType - ジェネレータが生成する結果の型。 floatdouble または long double のいずれかでない場合、効果は未定義です


[編集] メンバ型

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

[編集] メンバ関数

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

[編集] 非メンバ関数

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

[編集] ノート

いくつかの処理系は RealTypefloat の場合に、時折、無限大を返すことがあります。 LWG issue 2524 を参照してください。

[編集]

#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <random>
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 p : hist) {
        std::cout << std::fixed << std::setprecision(1) 
                  << p.first/2.0 << '-' << (p.first+1)/2.0 <<
                ' ' << std::string(p.second/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.