Subject: | _rand_seed() is constant under Win32 |
The new algorithm for _rand_seed introduced in v1.13 doesn't work under
Win32 (Windows XP, Strawberry perl v5.12.3) : so the sequence of
generated random numbers is the same at each execution !
The problem comes from the following lines in _rand_seed :
# Seed rand with the same gettimeofday-based formula that is
# used in Perl, and return an integer between 0 and 2**32-1.
my ($s, $u) = gettimeofday;
CORE::srand(1000003*$s+3*$u);
because 1000003*$s is too big for a 32-bit int, so the whole thing
becomes a float, and then that float is probably truncated or ignored
by CORE::srand.
Actually, the comment is wrong : the formula above is not exactly thhe
same that is used in Perl. In perl's util.c the code is :
u = (U32)SEED_C1 * when.tv_sec + (U32)SEED_C2 * when.tv_usec;
where the cast to (U32) is important.