
Dear all, Using the following (slightly manipulated) sample code of Boost.Random, I'm always gettig the same sequence: boost::mt19937 rng; boost::uniform_int<> six(1,6); boost::variate_generator<boost::mt19937, boost::uniform_int<> > die(rng, six); for(size_t i = 0; i < 10; ++i) cout << die() << " "; I know that this is the consequence of the fact that the generators are deterministic ones, plus another fact that they start using the same seed. This behaviour, however, is not that much desirable, and I'm seaking some sort of good random seed. Any suggestions? TIA and Merry Christmas, --Hossein __________________________________ Do you Yahoo!? Yahoo! Mail - You care about security. So do we. http://promotions.yahoo.com/new_mail

Hossein Haeri wrote:
Using the following (slightly manipulated) sample code of Boost.Random, I'm always gettig the same sequence:
boost::mt19937 rng; boost::uniform_int<> six(1,6); boost::variate_generator<boost::mt19937, boost::uniform_int<> > die(rng, six); for(size_t i = 0; i < 10; ++i) cout << die() << " ";
I know that this is the consequence of the fact that the generators are deterministic ones, plus another fact that they start using the same seed.
This behaviour, however, is not that much desirable, and I'm seaking some sort of good random seed. Any suggestions?
See: http://article.gmane.org/gmane.comp.lib.boost.user/8288/ for some suggestsions. HTH, Volodya

Hossein Haeri wrote:
This behaviour, however, is not that much desirable, and I'm seaking some sort of good random seed. Any suggestions?
It depends on your platform. /dev/urandom on Linux and possibly other Unixes, encapsulated by boost::random_device; CryptGenRandom on Windows.

Peter (Dimov),
It depends on your platform. /dev/urandom on Linux and possibly other Unixes, encapsulated by boost::random_device; CryptGenRandom on Windows.
Pardon? TIA, --Hossein __________________________________ Do you Yahoo!? The all-new My Yahoo! - What will yours do? http://my.yahoo.com

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. :-)

Paul (D),
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.
To be clear enough, I'm using Dev-C++ under windows. AFAIK, it uses GCC (3.3.1) and does some sort of simulation. What then? (Please :D)
Of course if time(0) meets your needs, go for it. :-)
Hmmm... Not sure. Let me test it. And a question about portability. Is <time.h> portable in C++? TIA, --Hossein __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
participants (3)
-
Hossein Haeri
-
Peter Dimov
-
Vladimir Prus