Tuesday, March 19, 2013
Bug - Stupid Random Number Generator rewrite
Using the new standard library C++0x random number generators is still an aquired taste.
Apparently if you initilise a bunch of random numbers together using the time clock, the value is truncated from a long long (__time64_t, time_t) down to an unsigned int....
I would assume that this involves dropping the MSB (most significant bits) but it seems not to. So rather than using the bits with the highest entropy, it uses the bits with the lowest and thus all the random number generators are seeded with the same value.... and generate the same sequence of numbers. Doh.
The solution is the use the std::random_device to seed the generators and then go from there. Sounds simple... and it apparently is .... but that did not stop the compiler throwing spurious errors yesterday afternoon on the same code that it happily compiles today. Remind me why I do this again?
Anyway, progress.
Removed one cpp file, two headers and now have less dependancies on boost. (Not a bad thing, just trying to simplify)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment