Created
September 4, 2017 12:38
-
-
Save jaycelq/9b5d85bfacd91433bc814d20cec1ce3d to your computer and use it in GitHub Desktop.
boost binomial distribution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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