构造分布。
// default constructor discrete_distribution(); // constructs using a range of weights, [firstW, lastW) template<class InputIterator> discrete_distribution(InputIterator firstW, InputIterator lastW); // constructs using an initializer list for range of weights discrete_distribution(initializer_list<double> weightlist); // constructs using unary operation function template<class UnaryOperation> discrete_distribution(size_t count, double xmin, double xmax, UnaryOperation weightfunc); // constructs from an existing param_type structure explicit discrete_distribution(const param_type& parm);
参数
firstW
从中构造分布的列表中的第一个迭代器。lastW
从中构造分布的列表中的最后一个迭代器(不包含此迭代器,因为迭代器末尾使用空元素)。weightlist
从中构造分布的 initializer_list。count
分布范围中的元素数。 如果 count==0,则等效于默认构造函数(始终生成零)。minx
分布范围中的最低值。maxw
分布范围中的最高值。weightfunc
表示分布的概率函数的对象。 参数和返回值都必须可转换为 double。parm
用于构造分布的参数结构。
备注
默认构造函数构造其存储的概率值仅具有附带值 1 的一个元素的对象。 这将产生始终生成零的分布。
迭代器范围构造函数,
template<class InputIterator>
discrete_distribution(InputIterator firstW, InputIterator lastW);
使用区间序列 [firstI, lastI) 上的迭代器中的权重来构造分布对象。
初始值设定项列表构造函数
discrete_distribution(initializer_list<double> weightlist);
使用初始值设定项列表 weightlist 中的权重来构造分布对象。
定义为以下内容的构造函数
template<class UnaryOperation>
discrete_distribution(size_t count, double xmin, double xmax, UnaryOperation funcweight);
构造根据以下规则初始化其存储的概率值的分布对象。 如果 count < 1,则 n = 1,并且等效于默认构造函数(始终生成零)。 如果 count > 0,则 n = count。 假如 0 < d = (maxw - minw)/n,使用 d 均匀子范围,每个权重分配如下:weightk = weightfunc(x),其中,对于 k = 0,...,n - 1,x = xmin + k * d + d/2。
定义为以下内容的构造函数
explicit discrete_distribution(const param_type& parm);
通过将 parm 用作存储的参数结构,构造分布对象。
要求
标头:<random>
命名空间: std