[random] streamable state of normal_distribution to ostream not accurate
Dear list members,
I'm using the Boost Random Number Library, and am now trying to store
the state of an instance of normal_distribution by means of its <<
operator. It doesn't however seem to work: three of its data members
are definitely not outputting properly on my system.
I can reproduce the problem with this test file:
-----
#include
mt19937 rng; normal_distribution<> gauss; variate_generator
> var(rng, gauss);
gauss is passed by value, and so var has a copy of it. This means that when you generate values with var, the state of gauss does not change.
cerr << gauss << endl; //dumps object internal state
The distribution() function of the variate_generator class returns a reference to the distribution being used. Try this instead: cerr << var.distribution() << endl; Then you should see the state changing; I did.
On Fri, Nov 7, 2008 at 12:44 AM, Dave Steenburgh
mt19937 rng; normal_distribution<> gauss; variate_generator
> var(rng, gauss); gauss is passed by value, and so var has a copy of it. This means that when you generate values with var, the state of gauss does not change.
Wow, thanks for helping me out there so fast. I completely missed this, and was especially confused because storing rng did work - which, I only now realise, is because that is passed by reference (something I did to share the generator among several variate_generators I suppose). Thanks. I'll sleep more sound now :)
participants (2)
-
Dave Steenburgh
-
Oei, YC