Skip to content

Instantly share code, notes, and snippets.

@jaycelq
Created September 4, 2017 12:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaycelq/9b5d85bfacd91433bc814d20cec1ce3d to your computer and use it in GitHub Desktop.
Save jaycelq/9b5d85bfacd91433bc814d20cec1ce3d to your computer and use it in GitHub Desktop.
boost binomial distribution
#include <time.h>
#include <vector>
#include <boost/random/binomial_distribution.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/variate_generator.hpp>
template<class T>
double gen_normal_3(T &generator)
{
return generator();
}
// Version that fills a vector
template<class T>
void gen_normal_3(T &generator,
std::vector<double> &res)
{
for(size_t i=0; i<res.size(); ++i)
res[i]=generator();
}
int main(void)
{
boost::variate_generator<boost::mt19937, boost::binomial_distribution<> >
generator(boost::mt19937(time(0)),
boost::binomial_distribution<>(10., 0.5));
for(size_t i=0; i<10; ++i)
std::cout<<gen_normal_3(generator)
<<std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment