In two recent posts, I've looked at seeding random number generators in in C++11 (looking at what's wrong with
std::seed_seq and developing something that avoids those flaws), but
seed_seq exists as a mechanism to “mix up” entropy that you give it. You still need to get that entropy from somewhere. So where?
std::random_device Is Not Your Friend
The obvious source for external randomness we can use in seeding is
std::random_device. But as I mentioned in this post,
- It's hard to make
std::random_deviceconform to the requirements of a seed sequence.
- It's unspecified just how costly this “device” is to read from.
- It may not be nondeterministic at all, rendering it unfit for our purposes.
Portable code needs to look to other sources of entropy for RNG seeding. And even if
std::random_device works well, mixing in entropy from other sources can have a variety of benefits, including performance.