std::discrete_distribution<IntType>::discrete_distribution
來自 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 &。 |
引數列表 | - | 分佈引數集 |
型別要求 | ||
-InputIt 必須滿足 LegacyInputIterator 的要求。 |