Boost 1.43似乎支持二项分布.您可以使用boost::variate_generator
将随机源连接到要从中进行采样的分布类型.
所以你的代码可能看起来像这样(免责声明:未经测试!):
boost::mt19937 rng; // produces randomness out of thin air
// see pseudo-random number generators
const int n = 20;
const double p = 0.5;
boost::binomial<> my_binomial(n,p); // binomial distribution with n=20, p=0.5
// see random number distributions
boost::variate_generator<boost::mt19937&, boost::binomial<> >
next_value(rng, my_binomial); // glues randomness with mapping
int x = next_value(); // simulate flipping a fair coin 20 times
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3859 次 |
最近记录: |