in reply to Re^2: Rand Wackiness!
in thread Rand Wackiness!

The rand function (on Win32) only produces values in the range 0 .. 32767*.

If you multiply that by any factor, you will get multiples of the base values. E.g.

#! perl -slw use strict; use Data::Dumper; my %hash; $hash{ int rand() * 65536 }++ for 1 .. 1e6; print "$_ => $hash{ $_ }" for sort{ $a <=> $b } keys %hash; __END__ 0 => 26 2 => 30 4 => 26 6 => 32 8 => 33 10 => 23 ... 65520 => 33 65522 => 28 65524 => 26 65526 => 24 65528 => 23 65530 => 26 65532 => 43 65534 => 26

Note how there are no odd values produced. The multiplier is a twice the base, so all you get are multiples of two.

If the multiplier is 3* the base, you only get powers of 3. And so on.

For non-exact multipliers, the pattern is less obvious, but there will still be (lots) of values that will never be produced.

Math::Random::MT has a much larger base, a huge periodicity, it's written in XS for reasonable speed and is available as a PPM from AS. Personally, I think it should have been included in Perl to replace CRT PRNGs years ago.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.