std:: lognormal_distribution
From cppreference.net
|
ヘッダーで定義
<random>
|
||
|
template
<
class
RealType
=
double
>
class lognormal_distribution ; |
(C++11以降) | |
対数正規分布乱数生成器は、以下の 対数正規分布 に従って乱数 x > 0 を生成します:
-
f(x; m,s) =
exp ⎛1 sx √ 2 π
⎜
⎝ -
⎞(ln x - m) 2
2s 2
⎟
⎠
パラメータ m と s は、それぞれ x の自然対数の平均と標準偏差です。
std::lognormal_distribution
は
RandomNumberDistribution
のすべての要件を満たします。
目次 |
テンプレートパラメータ
| RealType | - | ジェネレータによって生成される結果の型。これが float 、 double 、または long double のいずれでもない場合、動作は未定義です。 |
メンバー型
| メンバー型 | 定義 |
result_type
(C++11)
|
RealType |
param_type
(C++11)
|
パラメータセットの型、 RandomNumberDistribution を参照。 |
メンバー関数
|
(C++11)
|
新しい分布を構築する
(公開メンバ関数) |
|
(C++11)
|
分布の内部状態をリセットする
(公開メンバ関数) |
生成 |
|
|
(C++11)
|
分布内の次の乱数を生成する
(公開メンバ関数) |
特性 |
|
|
(C++11)
|
分布パラメータを返す
(公開メンバ関数) |
|
(C++11)
|
分布パラメータオブジェクトを取得または設定する
(公開メンバ関数) |
|
(C++11)
|
生成され得る最小値を返す
(公開メンバ関数) |
|
(C++11)
|
生成され得る最大値を返す
(公開メンバ関数) |
非メンバー関数
|
(C++11)
(C++11)
(removed in C++20)
|
二つの分布オブジェクトを比較する
(関数) |
|
(C++11)
|
擬似乱数分布に対するストリーム入出力を実行する
(関数テンプレート) |
例
このコードを実行
#include <cmath> #include <iomanip> #include <iostream> #include <map> #include <random> #include <string> int main() { std::random_device rd; std::mt19937 gen(rd()); std::lognormal_distribution<> d(1.6, 0.25); std::map<int, int> hist; for (int n = 0; n < 1e4; ++n) ++hist[std::round(d(gen))]; for (std::cout << std::fixed << std::setprecision(1); auto [x, y] : hist) std::cout << std::hex << x << ' ' << std::string(y / 200, '*') << '\n'; }
出力例:
2 3 *** 4 ************* 5 *************** 6 ********* 7 **** 8 * 9 a b c
外部リンク
| Weisstein, Eric W. "対数正規分布。" MathWorld — Wolfram Web リソースより。 |