命名空间
变体
操作

std::discrete_distribution<IntType>::discrete_distribution

来自 cppreference.cn
 
 
 
 
 
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,

                       UnaryOperation unary_op );
(4) (C++11 起)
explicit discrete_distribution( const param_type& params );
(5) (C++11 起)

构造一个新的分布对象。

1) 默认构造函数。使用单个权重 p = {1} 构造分布。此分布将始终生成 0
2) 使用范围 [firstlast) 中的权重构造分布。如果 first == last,则效果与默认构造函数相同。
3) 使用 weights 中的权重构造分布。实际调用 discrete_distribution(weights.begin(), weights.end())
4) 使用通过函数 unary_op 生成的 count 个权重构造分布。每个权重等于 wi = unary_op(xmin + δ(i + 0.5)),其中 δ =
(xmax − xmin)
count
i ∈ {0, ..., count − 1}。xminxmax 必须满足 δ > 0。如果 count == 0,则效果与默认构造函数相同。
5) 使用 params 作为分布参数构造分布。

[编辑] 参数

first, last - 定义用作权重的数字的元素范围。InputIterator 所引用的元素类型必须可转换为 double
weights - 包含权重的初始化列表
unary_op - 将应用的单目操作函数对象。

函数的签名应等效于以下内容

 Ret fun(const Type &a);

签名不需要有 const &
类型  Type 必须使得类型为 double 的对象可以被解引用然后隐式转换为  Type。类型 Ret 必须使得类型为 double 的对象可以被解引用并赋值为类型 Ret 的值。

参数列表 - 分布参数集
类型要求
-
InputIt 必须满足 LegacyInputIterator 的要求。