[Random] Good Truly-Random Seed
Dear all, May I please know what do you guys use as you "good truly-random seed"? TIA, --Hossein
On Wednesday 21 April 2010 16:31:21 Mathias Gaunard wrote:
May I please know what do you guys use as you "good truly-random seed"?
I use /dev/random
May I suggest that boost should have a cross-platform function to so this. time(NULL) is not random. A good hack would be xoring many "random" numbers that you can get: -time(NULL) -pid -the values fo uninitialised variables whatever you can think of
-----Original Message----- On 21 April 2010 13:47, Marius
wrote: May I suggest that boost should have a cross-platform function to so
this.
time(NULL) is not random.
It does, in the form of random_device, though for some reason it seems the Windows implementation still hasn't happened.
For Windows, I think the GetTickCount Windows API function should be sufficient for a random seed. -- Bill --
On 21 April 2010 13:46, Bill Buklis
For Windows, I think the GetTickCount Windows API function should be sufficient for a random seed.
I suspect that may lead to cold boot problems. Besides, it looks like the answer may be as simple as calling ADVAPI32!RtlGenRandom, rand_s, or similar http://en.wikipedia.org/wiki/CryptGenRandom.
On 21 Apr 2010, at 18:07, Scott McMurray wrote:
On 21 April 2010 13:47, Marius
wrote: May I suggest that boost should have a cross-platform function to so this. time(NULL) is not random.
It does, in the form of random_device, though for some reason it seems the Windows implementation still hasn't happened.
Yes, /dev/random which you will find in the random_device does this job well, and works fine for me on both linux and osx (dont know about windows). Its aim is to be a good source of random and unpredictable data, although its quality could vary with the amount and kind of random sources available to the kernel (eg. keystrokes). Read the man pages for details. What you mean by a good random seed depends on the application. In many cases it is sufficient to use the time (number of seconds since the epoch) as a seed (in C++ you can get the current time with std::time(0) using ctime). But if you use std::time(0) many times in quick succession it wont provide a good seed and can even return the same values if you call it quick enough (intervals less than a second). If you are running your program many times and need a new seed each time, then another strategy could be to save the state of your random generator when you have finished and use that state to initialise your program for the next run. Then your random numbers would only start to repeat after the period of the generator (which for most of them should be much longer than you need). If this is no good, you need hardware random number generators, of which there are many. You could also have a look at random.org.
Dear peterbarnabus,
In many cases it is sufficient to use the time
That's not enough for me.
If you are running your program many times and need a new seed each time, then another strategy could be to save the state of your random generator when you have finished and use that state to initialise your program for the next run.
This might do. I need to check.
If this is no good, you need hardware random number generators, of which there are many. You could also have a look at random.org.
Interesting website but that's not available as a piece of software usable directly on every machine. The application I am writing currently needs to be a standalone program runnable on every Windows. Cheers, --Hossein
On Wed, Apr 21, 2010 at 5:08 PM, Hossein Haeri
If this is no good, you need hardware random number generators, of which there are many. You could also have a look at random.org.
Interesting website but that's not available as a piece of software usable directly on every machine. The application I am writing currently needs to be a standalone program runnable on every Windows.
random.org just uses one of those quantum random number generator cards that generates true randomness, hence to be able to do the same thing on a client PC, you need to install one of those cards. The random_device in Boost should work fine on Windows too starting in 1.43, perhaps just target that?
random.org just uses one of those quantum random number generator cards that generates true randomness, hence to be able to do the same thing on a client PC, you need to install one of those cards.
I see.
The random_device in Boost should work fine on Windows too starting in 1.43, perhaps just target that?
Well, my deadline is quite close. When is 1.43 due? Cheers, --Hossein
On Apr 22, 2010, at 3:12 AM, Hossein Haeri wrote:
random.org just uses one of those quantum random number generator cards that generates true randomness, hence to be able to do the same thing on a client PC, you need to install one of those cards.
I see.
The random_device in Boost should work fine on Windows too starting in 1.43, perhaps just target that?
Well, my deadline is quite close. When is 1.43 due?
Boost releases happen near the first of Feb/May/Aug/November. So, 1.43 is due in out early May. (May 3rd, according to the calendar at http://www.boost.org/development/index.html ) If you look on the developer's list, 1.43 beta 1 has been built, and is being tested. -- Marshall
Dear Marshall,
The random_device in Boost should work fine on Windows too starting in 1.43, perhaps just target that?
Well, my deadline is quite close. When is 1.43 due?
Boost releases happen near the first of Feb/May/Aug/November. So, 1.43 is due in out early May. (May 3rd, according to the calendar at http://www.boost.org/development/index.html )
I'm afraid that's a few days late for our current deadline. But, thank you for letting me know; It'll be useful for our next iteration.
If you look on the developer's list, 1.43 beta 1 has been built, and is being tested.
I'm not sure I can afford the risk of using betas... :p --Hossein
Hossein Haeri wrote:
I'm not sure I can afford the risk of using betas... :p
Just replace random_device.cpp with the new version: http://svn.boost.org/svn/boost/trunk/libs/random/src/random_device.cpp
Dear Peter,
Just replace random_device.cpp with the new version:
http://svn.boost.org/svn/boost/trunk/libs/random/src/random_device.cpp
I'm afraid that doesn't work. Please see the P.S. for the compiler-log if it helps. Best, --Hossein P.S. D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:34: warning: ignoring #pragma comment D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:36: error: expected constructor, destructor, or type conversion before "const" D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: In constructor `boost::random_device::impl::impl(const std::string&)': D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:49: error: `CryptEnumProvidersA' was not declared in this scope D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:49: warning: unused variable 'CryptEnumProvidersA' D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: In member function `void boost::random_device::impl::error(const std::string&)': D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:80: warning: unused variable 'error_code' D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: At global scope: D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:169: error: `BOOST_RANDOM_DECL' does not name a type D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:175: error: `BOOST_RANDOM_DECL' does not name a type D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:182: error: expected constructor, destructor, or type conversion before "double" D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:187: error: expected constructor, destructor, or type conversion before "unsigned"
AMDG Hossein Haeri wrote:
Dear Peter,
Just replace random_device.cpp with the new version:
http://svn.boost.org/svn/boost/trunk/libs/random/src/random_device.cpp
I'm afraid that doesn't work. Please see the P.S. for the compiler-log if it helps.
Best, --Hossein
P.S.
D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:34: warning: ignoring #pragma comment D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:36: error: expected constructor, destructor, or type conversion before "const" D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: In constructor `boost::random_device::impl::impl(const std::string&)': D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:49: error: `CryptEnumProvidersA' was not declared in this scope D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:49: warning: unused variable 'CryptEnumProvidersA' D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: In member function `void boost::random_device::impl::error(const std::string&)': D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:80: warning: unused variable 'error_code' D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: At global scope: D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:169: error: `BOOST_RANDOM_DECL' does not name a type D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:175: error: `BOOST_RANDOM_DECL' does not name a type D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:182: error: expected constructor, destructor, or type conversion before "double" D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:187: error: expected constructor, destructor, or type conversion before "unsigned"
It looks like mingw defines its own versions of windows.h and wincrypt.h that are missing a few declarations. Try the attached patch against 1.42. In Christ, Steven Watanabe
Dear Steve,
It looks like mingw defines its own versions of windows.h and wincrypt.h that are missing a few declarations. Try the attached patch against 1.42.
Thank you for the patch. It unfortunately doesn't still completely work. The compile-log can again be found in the P.S. Any other suggestions? TIA, --Hossein P.S. D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:34: warning: ignoring #pragma comment D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: In constructor `boost::random_device::impl::impl(const std::string&)': D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:49: error: `CryptEnumProvidersA' was not declared in this scope D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:49: warning: unused variable 'CryptEnumProvidersA' D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: In member function `void boost::random_device::impl::error(const std::string&)': D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:80: warning: unused variable 'error_code'
AMDG Hossein Haeri wrote:
Dear Steve,
It looks like mingw defines its own versions of windows.h and wincrypt.h that are missing a few declarations. Try the attached patch against 1.42.
Thank you for the patch. It unfortunately doesn't still completely work. The compile-log can again be found in the P.S. Any other suggestions?
TIA, --Hossein
P.S.
D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:34: warning: ignoring #pragma comment D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: In constructor `boost::random_device::impl::impl(const std::string&)': D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:49: error: `CryptEnumProvidersA' was not declared in this scope D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:49: warning: unused variable 'CryptEnumProvidersA' D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp: In member function `void boost::random_device::impl::error(const std::string&)': D:/Sources/Boost/boost_1_42_0/libs/random/random_device.cpp:80: warning: unused variable 'error_code'
The patch actually creates libs/random/src/random_device.cpp. instead of libs/random/random_device.cpp In Christ, Steven Watanabe
Hi Steve,
The patch actually creates libs/random/src/random_device.cpp. instead of libs/random/random_device.cpp
Oops! I'd provided the wrong compile-log. Here is the correct one: D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:47: warning: ignoring #pragma comment In file included from D:\My Documents\My Contacts\Buisiness\MuSemantik\ACA\1\main.cpp:12: D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:224: error: redefinition of `const bool boost::random_device::has_fixed_range' D:/Sources/Boost/boost_1_42_0/boost/nondet_random.hpp:90: error: `const bool boost::random_device::has_fixed_range' previously defined here D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:225: error: redefinition of `const unsigned int boost::random_device::min_value' D:/Sources/Boost/boost_1_42_0/boost/nondet_random.hpp:91: error: `const unsigned int boost::random_device::min_value' previously defined here D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:226: error: redefinition of `const unsigned int boost::random_device::max_value' D:/Sources/Boost/boost_1_42_0/boost/nondet_random.hpp:92: error: `const unsigned int boost::random_device::max_value' previously defined here D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:249: warning: ignoring #pragma comment D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:251: error: duplicate initialization of boost::random_device::default_token D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:251: error: redefinition of `const char* const boost::random_device::default_token' D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:49: error: `const char* const boost::random_device::default_token' previously defined here D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:254: error: redefinition of `class boost::random_device::impl' D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:52: error: previous definition of `class boost::random_device::impl' D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:384: error: redefinition of `boost::random_device::random_device(const std::string&)' D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:182: error: `boost::random_device::random_device(const std::string&)' previously defined here D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:390: error: redefinition of `boost::random_device::~random_device()' D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:188: error: `boost::random_device::~random_device()' previously defined here D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:397: error: redefinition of `double boost::random_device::entropy() const' D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:195: error: `double boost::random_device::entropy() const' previously defined here D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:402: error: redefinition of `unsigned int boost::random_device::operator()()' D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:200: error: `unsigned int boost::random_device::operator()()' previously defined here TIA, --Hossein
AMDG Hossein Haeri wrote:
The patch actually creates libs/random/src/random_device.cpp. instead of libs/random/random_device.cpp
Oops! I'd provided the wrong compile-log. Here is the correct one:
D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:47: warning: ignoring #pragma comment In file included from D:\My Documents\My Contacts\Buisiness\MuSemantik\ACA\1\main.cpp:12: D:/Sources/Boost/boost_1_42_0/libs/random/src/random_device.cpp:224: error: redefinition of `const bool boost::random_device::has_fixed_range'
You either applied the patch twice or had an old version of libs/random/src/random_device.cpp when you applied the patch. You'll need to delete the extra parts. In Christ, Steven Watanabe
Steve,
You either applied the patch twice or had an old version of libs/random/src/random_device.cpp when you applied the patch. You'll need to delete the extra parts.
Done that and got the following link error: obj\Release\main.o:main.cpp:(.text+0x11fc): undefined reference to `CryptEnumProvidersA(unsigned long, unsigned long*, unsigned long, unsigned long*, char*, unsigned long*)@24' obj\Release\main.o:main.cpp:(.text+0x169c): undefined reference to `CryptEnumProvidersA(unsigned long, unsigned long*, unsigned long, unsigned long*, char*, unsigned long*)@24' Any suggestions now? TIA, --Hossein
AMDG Hossein Haeri wrote:
You either applied the patch twice or had an old version of libs/random/src/random_device.cpp when you applied the patch. You'll need to delete the extra parts.
Done that and got the following link error:
obj\Release\main.o:main.cpp:(.text+0x11fc): undefined reference to `CryptEnumProvidersA(unsigned long, unsigned long*, unsigned long, unsigned long*, char*, unsigned long*)@24' obj\Release\main.o:main.cpp:(.text+0x169c): undefined reference to `CryptEnumProvidersA(unsigned long, unsigned long*, unsigned long, unsigned long*, char*, unsigned long*)@24'
Any suggestions now?
You need to link to advapi32.lib In Christ, Steven Watanabe
AMDG Hossein Haeri wrote:
Done that and got the following link error:
obj\Release\main.o:main.cpp:(.text+0x11fc): undefined reference to `CryptEnumProvidersA(unsigned long, unsigned long*, unsigned long, unsigned long*, char*, unsigned long*)@24' obj\Release\main.o:main.cpp:(.text+0x169c): undefined reference to `CryptEnumProvidersA(unsigned long, unsigned long*, unsigned long, unsigned long*, char*, unsigned long*)@24'
Any suggestions now?
I didn't get the declaration quite right. It needs to be wrapped in extern "C" {}. In Christ, Steven Watanabe
Dear Steve,
obj\Release\main.o:main.cpp:(.text+0x11fc): undefined reference to `CryptEnumProvidersA(unsigned long, unsigned long*, unsigned long, unsigned long*, char*, unsigned long*)@24' obj\Release\main.o:main.cpp:(.text+0x169c): undefined reference to `CryptEnumProvidersA(unsigned long, unsigned long*, unsigned long, unsigned long*, char*, unsigned long*)@24'
Any suggestions now?
I didn't get the declaration quite right. It needs to be wrapped in extern "C" {}.
Yup, that finally does it. Thanks, --Hossein
Hi Scott,
It does, in the form of random_device, though for some reason it seems the Windows implementation still hasn't happened.
I'm not sure if this is because I'm using Windows or not. But, when I include the header and try to instantiate a random_device, my compiler (GCC) says it can't find the implementation of the ctor and the (virtual) dtor. I had a look at the header file and there was no definition over there. Had a quick search in the respective directories and couldn't find an implementation file either. Any suggestions? Cheers, --Hossein
AMDG Hossein Haeri wrote:
It does, in the form of random_device, though for some reason it seems the Windows implementation still hasn't happened.
I'm not sure if this is because I'm using Windows or not. But, when I include the header and try to instantiate a random_device, my compiler (GCC) says it can't find the implementation of the ctor and the (virtual) dtor. I had a look at the header file and there was no definition over there. Had a quick search in the respective directories and couldn't find an implementation file either. Any suggestions?
It's in libs/random/random_device.cpp, but depends on /dev/urandom. The implementation in 1.43 will contain an implementation for Windows as well. I can make a patch if you want one. In Christ, Steven Watanabe
Hi Steven,
It's in libs/random/random_device.cpp,
Yup, found the file.
but depends on /dev/urandom.
I see. And, that's why GCC complains that the nested class impl is not defined. Right? (GCC under MinGW under WinXP)
The implementation in 1.43 will contain an implementation for Windows as well. I can make a patch if you want one.
By all means please. :) (I can't wait for 1.43...) TIA, --Hossein
AMDG Marius wrote:
On Wednesday 21 April 2010 16:31:21 Mathias Gaunard wrote:
May I please know what do you guys use as you "good truly-random seed"?
I use /dev/random
May I suggest that boost should have a cross-platform function to so this. time(NULL) is not random.
A good hack would be xoring many "random" numbers that you can get: -time(NULL) -pid -the values fo uninitialised variables whatever you can think of
boost::random_device should work starting in Boost 1.43. In Christ, Steven Watanabe
On Wed, 21 Apr 2010 20:47 +0300, "Marius"
On Wednesday 21 April 2010 16:31:21 Mathias Gaunard wrote:
May I please know what do you guys use as you "good truly-random seed"?
I use /dev/random
May I suggest that boost should have a cross-platform function to so this. time(NULL) is not random.
A good hack would be xoring many "random" numbers that you can get: -time(NULL) -pid -the values fo uninitialised variables whatever you can think of
boost::uuids::detail::seed_rng found in boost\uuid\seed_rng.hpp provides a implementation of this. one can also call boost::uuids::detail::seed(UniformRandomNumberGenerator) Regards, Andy.
Dear Andy,
May I please know what do you guys use as you "good truly-random seed"?
I use /dev/random
May I suggest that boost should have a cross-platform function to so this. time(NULL) is not random.
A good hack would be xoring many "random" numbers that you can get: -time(NULL) -pid -the values fo uninitialised variables whatever you can think of
boost::uuids::detail::seed_rng found in boost\uuid\seed_rng.hpp provides a implementation of this.
one can also call boost::uuids::detail::seed(UniformRandomNumberGenerator)
Cool! Thanks. :) --Hossein
-----Original Message-----
May I please know what do you guys use as you "good truly-random seed"?
I use /dev/random
The best I've used is a true quantum randomness server at Formilab, which is based on radioisotope monitoring. Unfortunately, (at the time I was playing with it anyway) it was not available via a secure channel. TradeStation Group, Inc. is a publicly-traded holding company (NASDAQ GS: TRAD) of three operating subsidiaries, TradeStation Securities, Inc. (Member NYSE, FINRA, SIPC and NFA), TradeStation Technologies, Inc., a trading software and subscription company, and TradeStation Europe Limited, a United Kingdom, FSA-authorized introducing brokerage firm. None of these companies provides trading or investment advice, recommendations or endorsements of any kind. The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer.
participants (12)
-
Andy Tompkins
-
Bill Buklis
-
Hossein Haeri
-
John Dlugosz
-
Marius
-
Marshall Clow
-
Mathias Gaunard
-
OvermindDL1
-
Peter Dimov
-
peterbarnabus
-
Scott McMurray
-
Steven Watanabe