Here is an example to draw random numbers from a binomial distribution with std::binomial_distribution
#include <random>
int main ()
{
std::mt19937 eng(14);
std::binomial_distribution<size_t> dist(28,0.2);
size_t randomNumber = dist(eng);
return 0;
}
I am failing to find a similar example for boost. I went through this documentation, which explains how to compute PDF, CDF and others from a boost::math::binomial
object but they are not talking about sampling a random number.
Should I write a binary search myself based on the CDF that boost::math::binomial
will compute for me or can boost directly return random numbers?
Thanks to this link from @Bob__, here is a simple working example
For some reason, it would not compile with
size_t
, so I usedint
(see @Bob__'s comment below for more information).