std::piecewise_constant_distribution
提供: cppreference.com
ヘッダ <random> で定義 | ||
template<class RealType =double> class piecewise_constant_distribution; | (C++11以上) | |
std::piecewise_constant_distribution
は、各々が独自の重み w
i を持ついくつかの部分区間 [b
i, b
i+1) のそれぞれに一様に分布する、ランダムな浮動小数点数を生成します。 区間の境界の集合と重みの集合がこの分布のパラメータです。
i≤x<b
i+1 について、確率密度は
w i |
S (b i+1 - b i) |
std::piecewise_constant_distribution
は RandomNumberDistribution の要件をすべて満たします。
目次 |
[編集]テンプレート引数
RealType | - | ジェネレータが生成する結果の型。 float、 double または longdouble のいずれかでない場合、効果は未定義です |
[編集]メンバ型
メンバ型 | 定義 |
result_type | RealType |
param_type | パラメータセットの型、 RandomNumberDistribution を参照してください |
[編集]メンバ関数
新しい分布を構築します (パブリックメンバ関数) | |
分布の内部状態をリセットします (パブリックメンバ関数) | |
生成 | |
分布の次の乱数を生成します (パブリックメンバ関数) | |
特性 | |
分布のパラメータを返します (パブリックメンバ関数) | |
分布のパラメータオブジェクトを取得または設定します (パブリックメンバ関数) | |
生成される可能性のある最小値を返します (パブリックメンバ関数) | |
生成される可能性のある最大値を返します (パブリックメンバ関数) |
[編集]非メンバ関数
2つの分布オブジェクトを比較します (関数) | |
乱数分布に対してストリーム入出力を行います (関数テンプレート) |
[編集]例
Run this code
#include <iostream>#include <string>#include <map>#include <random> int main(){std::random_device rd;std::mt19937 gen(rd());// 50% of the time, generate a random number between 0 and 1// 50% of the time, generate a random number between 10 and 15std::vector<double> i{0, 1, 10, 15};std::vector<double> w{1, 0, 1}; std::piecewise_constant_distribution<> d(i.begin(), i.end(), w.begin()); std::map<int, int> hist;for(int n=0; n<10000;++n){++hist[d(gen)];}for(auto p : hist){std::cout<< p.first<<' '<<std::string(p.second/100, '*')<<'\n';}}
出力:
0 ************************************************** 10 ********** 11 ********* 12 ********* 13 ********** 14 *********