Hashing seeds is a common idea taught to people, but a bad one.
See, the problem is that the
seed is supposed to be a
random index into your random sequence. Same seed == same random numbers.
Unfortunately, there isn’t a whole lot of “random” you can choose from for a seed; the clock is your easiest target. But when you are seeding more often than the clock can provide different numbers (multiple times a second)* people start to look around to figure out what more they can mix into the seed value.
*
which, BTW, is a design flaw —you shouldn’t be seeding RNGs a whole bunch of times. Seed one RNG, and use it over and over, even if it is to use it as a seed function for your multiple-times-a-second RNGs.
Common things to mix in are PID or network connection ID and the like —which is to say, they are hashing in stuff that is completely
non-random to try to increase randomness. It may appear to work to some degree, but anyone who pays attention to their RNG responses at some point realize something went wrong...
And the common wisdom doesn’t really know how to fix that.
The correct answer is to use a single RNG as your seed
s source function, or, better yet, avoid using multiple RNGs altogether and stick to the one.
────────
Entropy has nothing to do with your seed. As simply put as possible, entropy is the idea that your TRNG source has been sufficiently randomized by observed “random” events. More accurately, entropy is a measure of how well-randomized your TRNG is.
For example, when the computer first starts up, there hasn’t been enough time to observe randomness: your TRNG source is not very random*. Only after the computer has been running for a while has enough “entropic events” (random-ish stuff) been observed to make the TRNG source pool sufficiently random.
*
and can be observed, and then guessed, which is why bootup is an easy, known point of failure in secure random computing. The way this is overcome is to regularly cache the current random pool, so at bootup the random pool can be reinitialized using its prior value. That, and make it harder for observers to reboot your computer.
────────
Now, in this post alone we have considered two different kinds of random number generators: pseudo-devices whose source pool we need to seed, and true-devices that we let the OS (or other underlying system) manage. (Believe me, this is a simplification.)
To seed a PRNG we need some sufficiently “random” source, such as the system clock —which, as you are probably thinking right now, really isn’t all that random (because it isn’t).
The random quality of the system clock comes from the idea that your PRNG is not regularly seeded, but it IS seeded at a relatively random event, such as whenever the user starts your program up. If the user sets your program to run at exactly 3 AM every day, there is a problem...
However, for most pseudo-random needs, such as video games and the like, it is sufficient.
For things like preparing a crypto document (think HTTPS connection using SSL), it is not. For that you need the system’s CSPRNG. How the CSPRNG works underneath is a whole post in itself that I’ll... not go into right now, but it is sufficient to say that the numbers you pull from it can be considered true noise.
I hope you also see how “entropy” is a relatively useless number, as its ends of measurement are
not defined. All you can say is that zero means there is absolutely no entropy in the system, which is definitely
not something you want to tell people, and non-zero means there is some degree of entropy in the system, even a possibly useless amount (such as a
single event update).
Further, and the problem with
std::random_device, user programs are not likely to have
access to the OS’s measure of entropy (or at least, they shoudn’t), so the standard merely says it may provide you a number, but acknowledges that any number you get from it might not mean anything for any number of reasons.
Ignore
entropy(). Like the rest of
std::random_device, it is designed to fail without necessarily making you aware.
And... after writing all this, I need to go and finish writing my random number FAQ.