- random[meta header]
- std[meta namespace]
- class template[meta id-type]
- [mathjax enable]
- cpp11[meta cpp]
namespace std {
template <class RealType = double>
class exponential_distribution;
}
exponential_distribution
は、連続確率分布の一種である指数分布を表すクラスである。指数分布は、ガンマ分布(gamma_distribution
)の形状母数(scale parameter)を1.0とした特殊ケースとして定義される。
以下の確率密度関数に基いて、浮動小数点数の値x
を生成する:
この数式におけるλ(lambda)は、ある事象が起こってから次にまた発生するまでの間隔を表す。
指数分布は、以下のような用途に使用できる:
- 銀行の窓口に顧客が到着する時間間隔
- 発作を起こしてから死亡するまでの時間間隔
テンプレートパラメータは、以下を意味する:
RealType
: 生成する実数の型。
名前 | 説明 | 対応バージョン |
---|---|---|
(constructor) |
コンストラクタ | C++11 |
~exponential_distribution() = default; |
デストラクタ | C++11 |
reset |
状態をリセットする | C++11 |
名前 | 説明 | 対応バージョン |
---|---|---|
operator() |
乱数を生成する | C++11 |
名前 | 説明 | 対応バージョン |
---|---|---|
lambda |
母数を取得する | C++11 |
param |
分布のパラメータを取得/設定する | C++11 |
min |
生成し得る値の下限を取得する | C++11 |
max |
生成し得る値の上限を取得する | C++11 |
型 | 説明 | 対応バージョン |
---|---|---|
result_type |
乱数生成結果の実数型 RealType 。 |
C++11 |
param_type |
分布パラメータの型。未規定。 | C++11 |
名前 | 説明 | 対応バージョン |
---|---|---|
operator== |
等値比較 | C++11 |
operator!= |
非等値比較 | C++11 |
operator<< |
ストリームへの出力 | C++11 |
operator>> |
ストリームからの入力 | C++11 |
#include <random>
#include <fstream>
int main()
{
std::random_device seed_gen;
std::default_random_engine engine(seed_gen());
std::exponential_distribution<> dist(1.0);
std::ofstream file("exponential_distribution.tsv");
for (std::size_t n = 0; n < 1000; ++n) {
// 指数分布で乱数を生成する
double result = dist(engine);
file << result << "\t\n";
}
}
- std::exponential_distribution[color ff0000]
- std::ofstream[link /reference/fstream/basic_ofstream.md.nolink]
- dist(engine)[link exponential_distribution/op_call.md]
このプログラムによってある時に得られた結果(exponential_distribution.tsv)を図示する。
- C++11
- Clang:
- GCC:
- GCC, C++11 mode: 4.7.2
- ICC:
- Visual C++: