Namespaces
Variants

std::discrete_distribution<IntType>:: discrete_distribution

From cppreference.net
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) 使用范围 [ first , last ) 内的权重构造分布。若 first == last ,效果与默认构造函数相同。
3) 使用 weights 中的权重构造分布。实际调用 discrete_distribution ( weights. begin ( ) , weights. end ( ) )
4) 使用函数 unary_op 生成 count 个权重来构造分布。每个权重等于 w i = unary_op(xmin + δ(i + 0.5)) ,其中 δ =
(xmax − xmin)
count
i ∈ {0, ..., count − 1 }。 xmin xmax 必须满足 δ > 0 。若 count == 0 ,其效果与默认构造函数相同。
5) 使用 params 作为分布参数来构造该分布。

参数

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

函数签名应等效于:

Ret fun ( const Type & a ) ;

签名不需要包含 const &
类型 Type 必须满足: double 类型的对象可被解引用并隐式转换为 Type 。类型 Ret 必须满足: double 类型的对象可被解引用并赋以 Ret 类型的值。 ​

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