Initializing Perl's rand

Doug.Palmer at Doug.Palmer at
Wed Jun 26 09:51:04 EST 2002

> As aaid elsewhere, if the rand() function is any good, then 
> hashing time() 
> will give no additional benefit.

If the rand() function is any good. 

Perl 5.6.1 tries to use the following library functions: drand48(), random()
and rand(). If rand() is the only function available, then it will be used.
And rand() is, often, not a good random number generator at all -- see
"Numerical Recipes in C", section 7.1. I've got no idea what MacPerl uses,
but I think a little suspicion is in order.

Properly hashing time() (not just multiplying it by a prime and crossing
your fingers) will at least ensure that any changes in the low order bits of
time are well distributed and mixed into the seed. This should lower the
chances of rand() coming up with the same sequence thanks to changes in low
order bits in the seed not percolating into the random number quickly;
you're at least starting from a significantly different position. 

The proof of the pudding is in the eating. Using Crypt::SHA, Math::RandomOrg
or whatever shouldn't require that much in the way of drastic surgery to see
what happens. If you want a more solid test, have a look at

More information about the linux mailing list