I have finished installing Boost, and I am (finally) using it in my program. What I wanted was to be able to generate
- Randomly distributed numbers between 0 and 1
- Normally distrubted numbers with standard deviation 1
I have accomplished this by the following header file:
#include <boost/random/normal_distribution.hpp>
#include <boost/random/uniform_real.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/variate_generator.hpp>
boost::mt19937 rng;
boost::normal_distribution<double> nd(0.0, 1.0);
boost::variate_generator< boost::mt19937, boost::normal_distribution<double> > normal(rng, nd);
boost::uniform_real<float> ur(0.0, 1.0);
boost::variate_generator< boost::mt19937, boost::uniform_real<float> > uniform(rng, ur);
I have two questions:
- Is my approach correct? So far it seems consistent in that I get the desired behavíor and it seems like other people do it this way too
- I need to simulate a very large sample, and consequently I need a very large number of random numbers, much greater than 10^9. Is there a more efficient way to achieve this than my approach of simply calling uniform() and normal()?