Boost logo

Boost Users :

Subject: Re: [Boost-users] seed for pseudiorandom generator
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2012-08-26 18:40:18


AMDG

On 08/25/2012 03:17 PM, Kraus Philipp wrote:
> Hello,
>
> I'm updating some algorithms and I need a tip for initialisation of the boost mersenne twister. I think the ctime is not a very good initialization. I think about a uuid value of the OS.
> I use also the non-deterministic generator, but I need an idea for the mersenne twister initialization.
>
> Do you have an idea?
>

Well, you can use random_device to get a seed:

random_device rng;

mt19937 prgn1(rng()); // seed with one random value

std::vector<uint32_t> vec;
for(int i = 0; i < NUM_SEED_WORDS; ++i) {
  vec.push_back(rng());
}
seed_seq seed(vec);
mt19937 prng2(seed); // seed with a fixed number of words

mt19937 prng3(rng); // fill the entire initial state randomly

In Christ,
Steven Watanabe


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net