Hasty Briefsbeta

Bilingual

C++ Seeding Surprises (2015)

10 months ago
  • #Programming
  • #Random Number Generation
  • #C++
  • C++11's std::seed_seq is intended to improve random number generator seeding but has limitations.
  • Using a single 32-bit integer to seed a large state RNG like Mersenne Twister leads to predictability and bias issues.
  • std::seed_seq can introduce bias even when provided with sufficient seed data, as it's not a bijection.
  • Initializing RNGs with insufficient seed data can result in missing or duplicated outputs, causing systemic bias.
  • The Mersenne Twister requires 19937 bits of seed data for unbiased initialization, making smaller seeds problematic.
  • std::seed_seq's design forces its use even when unnecessary, complicating proper seeding with std::random_device.
  • Proposed fixes include relaxing Seed Sequence requirements and adding a generate method to std::random_device.