I have a function that should simulate a new random exponential variable every time it is called:
#include <boost/random.hpp> //Simulates a single exponential random variable double generateExponential(double lambda) { boost::mt19937 rng; //Mersenne Twister Generator rng.seed(time(0)); boost::variate_generator< boost::mt19937&, boost::exponential_distribution<> > rndm(rng, boost::exponenti\ al_distribution<>(lambda)); return rndm(); } for example,
double newExp = generateExponential(10); However, each time I call the function, it generates the same random number. I want it to generate a different random number each time the function is called. I thought "rng.seed(time(0))" might fix it but it hasn't. How could I get it to do this?
mt19937was added to C++11; if you have C++11 available then you can improve on this function