Random number generation

I'm using the following code to generate a random 64 bit value: boost::mt19937 rng; boost::uniform_int<uint64_t> r(0,0xffffffffffffffff); boost::variate_generator<boost::mt19937&, boost::uniform_int<uint64_t> > gen(rng, r); uint64_t id = gen(); However it seems it's not random on each execution of the program? (rather I get the same value again). How do I randomise this properly?

Hi David, You need to seed the random number generator upon creation, default contructed it will always be in the same state. Best, Dee On Mon, Mar 8, 2010 at 4:29 PM, David Kaplan <davkaplan@gmail.com> wrote:
I'm using the following code to generate a random 64 bit value:
boost::mt19937 rng; boost::uniform_int<uint64_t> r(0,0xffffffffffffffff); boost::variate_generator<boost::mt19937&, boost::uniform_int<uint64_t> > gen(rng, r); uint64_t id = gen();
However it seems it's not random on each execution of the program? (rather I get the same value again). How do I randomise this properly?
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users

AMDG David Kaplan wrote:
On 8 March 2010 12:39, Diederick C. Niehorster <dcnieho@gmail.com> wrote:
You need to seed the random number generator upon creation, default contructed it will always be in the same state.
Thanks - what's the syntax for doing that?
Pass an integer to the constructor or call seed. The easiest way is boost::mt19937 gen(std::time(0)); In Christ, Steven Watanabe
participants (3)
-
David Kaplan
-
Diederick C. Niehorster
-
Steven Watanabe