std::discrete_distribution<IntType>::discrete_distribution
来自 cppreference.cn
< 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) 构造具有 count 个权重的分布,这些权重使用函数 unary_op 生成。 每个权重等于 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 | - | 将要应用的unary operation函数对象。 函数的签名应等效于以下内容 Ret fun(const Type &a); 签名不需要具有 const &。 |
params | - | 分布参数集 |
类型要求 | ||
-InputIt 必须满足 LegacyInputIterator 的要求。 |