如何使用double[];初始化boost::random::discrete_distribution;
How to initialize boost::random::discrete_distribution using double[];
我想用一个双[]初始化boost::random::discrete_distribution,如下所示:
boost::random::discrete_distribution<>* distribution(double* _distr)
{
return new boost::random::discrete_distribution<>(_distr);
}
我知道我可以使用向量或静态大小的表,但有没有一种方法可以在不重写_distr的情况下克服这一点?
discrete_distribution<>
不能接受普通的double*
参数,因为它无法知道数组的长度。
相反,它需要一个迭代器范围,但您必须指定数组中的元素数量:
boost::random::discrete_distribution<>* distribution(double const* distr,
std::ptrdiff_t count)
{
return new boost::random::discrete_distribution<>(distr, distr + count);
}
和往常一样,这一点在文档中非常清楚。
相关文章:
- <random>在实践中应该实际使用哪个随机数引擎? std::mt19937?
- 是否可以为boost::random::uniform_int_distribution<>设置确定性种子?
- 'generate'不是窗口头文件中'std::random_device'的成员<random>
- 数组打印"random"值时出现问题
- 使用""的不可重现的随机数<random>
- <random> 尽管不是常量,但所有发行版都是线程安全的吗?
- 从时间生成'random'数字?
- 无法在 c++ 中包含"random"头文件
- Nemiver 找不到文件 /build/glibc-LK5gWL/glibc-2.23/stdlib/random.c
- 如何在 c++ 中正确读取 GRC 块"Random Source"的字节输出数据到自己的 OOT 块中?
- 如何从C++<random>获得一致的行为
- 为什么 random() 在窗口中不起作用
- 等效于C++中的numpy.random.choice函数
- Arduino 的新手。 "Random"值在复位时重复
- 在 c++ 中反转数组时,为什么在输入和输出之间得到一个"random"数字?
- 如何使用<random>填充标准::数组
- stdlib.h's random() on MS Visual Studio 2008
- Boost::random::discrete_distribution构建后如何更改权重
- 使用 和 函数生成随机双向量<random>
- 程序在每次执行时生成相同的'random'编号