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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.