Boost logo

Boost :

Subject: [boost] [Random]Random value from range
From: Mariusz Kwiczala (mariusz.kwiczala_at_[hidden])
Date: 2010-01-03 11:41:25


Hello,

After experiments I wrote below function.
Could you verify if function is written correctly for random value from
range [min,max) and
uniform distribution?

double RandomGenerator(const double min, const double max)
{
assert(min<max);
static boost::lagged_fibonacci44497 gen(static_cast<unsigned
int>(std::time(0)));
static boost::uniform_real<> range(min, max);
static boost::variate_generator<boost::lagged_fibonacci44497&,
boost::uniform_real<> > generator(gen, range);
const double value = generator();
return value;
}

I have few question related to random library:
1. Is it possibility to write function which will generate numbers
from range [min, max] or (min, max)
2. Why generator (boost::lagged_fibonacci44497)is not properly
initialized in some default constructor. Without static_cast<unsigned
int>(std::time(0)) code generated the same values after every application
run.
3. Why when I missed reference "&" in line
boost::variate_generator<boost::lagged_fibonacci44497&, application crashes.

Is it bug?

 

Best regards,

Mariusz

 

 


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk