std::discrete_distribution<IntType>::discrete_distribution
From cppreference.com
< cpp | numeric | random | discrete distribution
| discrete_distribution(); |
(1) | (C++11以降) |
| template< class InputIt > discrete_distribution( InputIt first, InputIt last ); |
(2) | (C++11以降) |
| discrete_distribution( std::initializer_list<double> weights ); |
(3) | (C++11以降) |
| template< class UnaryOperation > discrete_distribution( std::size_t count, double xmin, double xmax, |
(4) | (C++11以降) |
| explicit discrete_distribution( const param_type& params ); |
(5) | (C++11以降) |
新しい分布オブジェクトを構築します。
1) デフォルトコンストラクタ。単一の重みp = {1}で分布を構築します。この分布は常に0を生成します。
2) 重みが範囲
[first, last)にある分布を構築します。first == lastの場合、デフォルトコンストラクタと同じ効果があります。3) 重みがweightsにある分布を構築します。discrete_distribution(weights.begin(), weights.end())を効果的に呼び出します。
4) 関数unary_opを使用して生成されるcount個の重みを持つ分布を構築します。各重みはwi = unary_op(xmin + δ(i + 0.5))に等しく、ここでδ =
およびi ∈ {0, ..., count − 1}です。xminおよびxmaxはδ > 0となるようにする必要があります。count == 0の場合、デフォルトコンストラクタと同じ効果があります。
| (xmax − xmin) |
| count |
5) 分布パラメータとしてparamsを持つ分布を構築します。
[編集] パラメータ
| first, last | - | 重みとして使用される数値を定義する要素の範囲。InputIteratorが参照する要素の型は、doubleに変換可能である必要があります。 |
| weights | - | 重みを含む初期化子リスト |
| unary_op | - | 適用される単項演算関数オブジェクト。 関数のシグネチャは以下と同等である必要があります。 Ret fun(const Type &a); シグネチャは const & を持つ必要はありません。 |
| params | - | 分布パラメータセット |
| 型要件 | ||
-InputIt は LegacyInputIterator の要件を満たす必要があります。 | ||