|
Boost : |
Subject: Re: [boost] Problem with boost::random seed
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2011-01-27 21:31:19
AMDG
On 1/27/2011 6:18 PM, Anton Skvorts wrote:
> I'm still having some problems with boost::random, obviously because I
> don't fully understand all that s going on... Read the documentation
> and your post but still cannot find what is wrong with my code
> bellow:
>
Notice that you have two separate variate_generators,
one in the main code, and one for each call to normalReseed.
Each normal_distribution object has its own cache.
When you call reset, you need to make sure that
you call it on the distribution that you are using.
> extern "C" __declspec(dllexport) double normalReseed(double mean,
> double sigma, uint32_t x){
> boost::normal_distribution<> normal(mean,sigma);
> boost::variate_generator<boost::mt19937&,
> boost::normal_distribution<> > rng(gen, normal);
> rng.engine().seed(x);
> rng.distribution().reset();
> return rng();
> }
> boost::mt19937 gen;
> boost::normal_distribution<> normal(0,1);
> boost::variate_generator<boost::mt19937&,
> boost::normal_distribution<> > die(gen, normal);
> cout<< rng()<< endl;
> cout<< rng()<< endl;
> cout<< rng()<< endl;
> cout<< normalReseed(0, 1, 0)<< endl;
> cout<< rng()<< endl;
> <snip>
>
> Possibly are again cached results from Box-Muller algorithm the reason
> for this pattern but still cannot see why we get these results,
> neither how to overcome this problem
>
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk