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) 使用通过函数 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 的要求。 |