4 ms·
See the author's comments on very similar code here: https://www.reddit.com/r/cpp/comments/31857s/random_number_generation_it_might_be_harder_than/cq00h6y http
by Veedrac 11y ago
See the author's comments on very similar code here:
https://www.reddit.com/r/cpp/comments/31857s/random_number_generation_it_might_be_harder_than/cq00h6y https://www.reddit.com/r/cpp/comments/31857s/random_number_g...
> One minor issue is that you’re using `default_random_engine`, which in some systems may be a LCG with a tiny 32-bit state. If so, you’ll have an RNG with a tiny period. That’s why Stephan recommends[1] that you explicitly use the Mersenne Twister. Of course, it might be something better, with more state.
> But what’s really wrong with it is that you use a single 32-bit integer to seed the RNG. If you’re using the Mersenne Twister, you’re using four bytes of state to try to seed 624 bytes. It’ll work, but it’s way worse than what the Python code does; Python uses 624 bytes of actual entropy rather than four bytes.
[1]: https://www.reddit.com/r/cpp/comments/31857s/random_number_generation_it_might_be_harder_than/cpz7coh https://www.reddit.com/r/cpp/comments/31857s/random_number_g...
- cbsmith 11y agoI think the solution for platforms which use bad default_random_engine's is for said platforms to stop doing that. ;-) Seriously, the whole point of platform defaults is that they make appropriate choices for the platform. Sure, you can define your own engine, but that's exactly what the original API gives you...
- Veedrac 11y agoYou could say that about a lot of platform defaults. Sadly it's still our responsibility to avoid the bad ones.
- cbsmith 11y agoExactly. Working around it in the standard is the wrong way to do it though. You send what the standard requires, and maybe the bad guys are standards compliant, but there is no point in bending over backwards to work around a platform that is going to find a way to mess it up anyway.
- cbsmith 11y agoNow I finally get it. C++11's seed sequences are not compatible with std::random_device. I'd been using the pre-C++11 boost::random and hadn't realized there was this subtle difference. That is super annoying.