I Just Wanted a Random Integer!
summary
Using rand()+modulo fails unit tests: low bits bias misses edge cases, and random_device is hardware dependent, can block or throw. Seeding mt19937 with random_device then using std::uniform_int_distribution gives repeatable tests; mt19937 generates 1e9 ints in ~3.6s vs random_device ~44s, but initializing mt19937 a million times costs ~15s. PCG implementations are ~2.5× faster and much smaller. Integer distributions are cheap to construct; always log seeds and benchmark performance.
AI-written summary · about
chapters (11)
- 0:00Introduction and DNA context
- 3:12Bad random number habits
- 10:00What is entropy?
- 12:37Random device explained
- 18:44Generators and Mersenne Twister
- 22:14Guidelines from STL's talk
- 26:50History of Mersenne and PCG
- 33:14PCG random number generator
- 36:08Uniform distribution in loops
- 43:37Engineering judgment over rules
- 47:11Conclusion and benchmarking advice








