The point of hashing the result of time
is to avoid a predictable seed value. It would be used in a situation where you might be alright with an insecure pseudo-random number generator like rand
, but still not want clients to be able to predictably determine your pseudo-random sequence.
There's lot's of ways that you can accomplish hashing the time_t
. One very simple naive approach is to simply xor the running process pid. This is a classic approach that Unix systems have used for a long time; although, it doesn't really add that much more in the form of security. You could also include other forms of real entropy from the system. Other alternatives would involve a proper hash function or some combination of other data points and hashes. Examples of hashing functions include Bernstein's hash, the Fowler–Noll–Vo hash or other cryptographically secure hashes like MD5 or SHA1. However, if you're going to use a cryptographically secure hashing function, you should probably be using a cryptographically secure random number generator as well.
For what it is worth, since this is tagged with C++, you can use the built-in std::hash
function provided in the standard library as long as you are using a C++ compiler that supports TR1 or later. In GCC, the std::hash
function is implemented using the FNV hash mentioned above.