It could depend of your operating system. I would imagine that recent GNU/Linux kernels might use the hardware random generators for e.g. /dev/random
(since the random(4)
man page suggest that it uses noise), but I could be wrong.
The usual practice is to use some common pseudo-random generator (like e.g. the random(3)
standard function), but to seed it, when starting your application, from some more random source (e.g. reading /dev/urandom
, using getpid()
and something from the current time with gettimeofday()
, etc).
Very probably, getting very good random numbers is a black art, at least for me. But the above solution has at least the advantage of not being easily reproducible from one application run to another.
If your application is long lasting (e.g. a web service running in a the same single process for many hours) you might perhaps re-seed your Pseudo Random Number Generator from time to time. For a web server, I would imagine you could also use request times (measuring them with millisecond granularity) as a source of randomness (to seed your PRNG).