: Can anyone tell me what is usualy used as the seed for srand(unsigned int)
: ATM I'm using
: srand((unsigned int)time())
: but I've got the feeling that's not the best way to do it.
It depends on what your application is. If you're making a game, then
this should be fine. If you are making an encryption algorithm, this is
not okay. Basically, if you think that there is a problem with the
random stream being hacked, then make a stronger PRNG.
The way I'm currently doing a cryptographically secure PRNG is:
(oh...I'm doing this in Java)
Throw up a window.
Record mouse movements in it
Hash the mouse movements with SHA-1
Use the hashed output of SHA-1 as the key to RC4.
Send the RC4 an one-byte Initialization Vector
Use the output of the RC5 as the random number stream
also use that as the next block to encrypt.
mouse movements are sufficiently random for the SHA-1 seed
SHA-1 produces a cryptographically sound random seed
RC4 is decently fast and can work a byte at a time
But, for a game, this is totally overkill.
: Thomas Needham (Mandrake)
I got a coffee mug from Cray Research when they moved out. Now I can
drink my coffee while doing 63 other, unrelated tasks.