Hello
I'm sorry if this is answered in the documentation, but I didn't find
it. I want a function which returns a normally distributed number.
#include
#include
using namespace boost;
double SampleNormal (double mean, double sigma) {
mt19937 rng; // select random number generator
rng.seed((unsigned int) time(0)); // seconds since 1970
// select desired probability distribution
normal_distribution<double> norm_dist(mean, sigma);
// bind random number generator to distribution, forming a function
variate_generator
normal_sampler(rng, norm_dist);
// sample from the distribution
return normal_sampler();
}
This (from http://surl.se/tvk) works very well, except if it's invoked
(with same parameters) more often than once a second. If so, the
generator gets equal seeds and returns equal values. How can I construct
my program so the seeding happens only once?
My experience with templates is limited, but I do have a grasp of the idea.
Thanks for any hints.
Snorre Jakobsen, Norway