Boost logo

Boost Users :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2004-12-24 16:22:47


Hossein Haeri wrote:
> Peter (Dimov),
>
>> It depends on your platform. /dev/urandom on Linux
>> and possibly other
>> Unixes, encapsulated by boost::random_device;
>> CryptGenRandom on Windows.
>
> Pardon?

Your question was "how do I obtain a good random seed". If you need high
quality randomness that is hard to predict, you need a source of entropy,
that is, a "real" random number generator. On Linux such an entropy source
is available as the /dev/urandom device, which you can read as an ordinary
file. You can pass a boost::random_device to the constructor of your engine
so it can seed itself from /dev/urandom.

On Windows there is no /dev/urandom, but you can generate a high-quality
random seed with CryptGenRandom. This function uses a number of essentially
random values in the Windows kernel as an entropy source.

Of course if time(0) meets your needs, go for it. :-)


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