|
Boost : |
Subject: [boost] problems with the Random library in Boost v1.47
From: Hongyu Miao (jackymiao_at_[hidden])
Date: 2011-07-13 14:35:11
Hi, All
Sorry to bother you with this. I met a problem with the Random library in
the latest release v1.47.
The following code works well for v1.46.1:
double unirand_real(double a, double b)
{
// Create a random number generator engine
static boost:: mt19937 rng_real(static_cast<unsigned
int>(std::time(0)));
// select Uniform probability distribution
boost::uniform_real<double> dist(a, b);
// bind random number generator to distribution, forming a function
boost:: variate_generator < boost:: mt19937 &,
boost::uniform_real<double> > sampler(rng_real, dist);
// sample from the distribution
return sampler();
}
However, when I adopted my code to v1.47, the following code failed due to
memory access violation after a number of function calls:
double unirand_real(double a, double b)
{
// Create a random number generator engine
static boost::random::mt19937 rng_real(static_cast<unsigned
int>(std::time(0)));
// select Uniform probability distribution
boost::random::uniform_real_distribution<> dist(a, b);
// return random sample
return dist(rng_real);
}
I will appreciate your help with this problem as right now I think the
Random library may have a bug.
Best,
Jacky
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk