Skip to content

Instantly share code, notes, and snippets.

@kohnakagawa
Created April 22, 2014 10:09
Show Gist options
  • Save kohnakagawa/11172913 to your computer and use it in GitHub Desktop.
Save kohnakagawa/11172913 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <boost/random.hpp>
int main ()
{
using namespace boost;
using namespace std;
mt19937 gen(100);
//normal distribution
normal_distribution<> dst(0.,1.0); //(mean,deviation)
variate_generator<mt19937&,normal_distribution<> > rand_normal(gen,dst);
for(int i=0; i<10; ++i) {
double result = rand_normal();
cout << result << endl;
}
//uniform distribution
uniform_real<> range(0,1);
variate_generator<mt19937&,uniform_real<> > rand_uniform(gen,range);
for(int i=0; i<10; ++i){
double result = rand_uniform();
cout << result << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment