Welcome to the Monastery | |
PerlMonks |
Re^4: Is rand() really that slow or am I just using it wrong?by BrowserUk (Patriarch) |
on Aug 09, 2013 at 00:03 UTC ( [id://1048667]=note: print w/replies, xml ) | Need Help?? |
I still don't quite understand why this was only an issue on windows The default rand (from the MS CRT) only produces 15-bits of randomness. Ie. int( rand*2**15 ) produces: 0 .. 32767. If you multiply by a larger factor, there are gaps in the range of values produced. Eg. int( rand() * 65535 ) produces 32767 unique values: 0 .. 65535 step 2. Hence your problem. Used as is, it will never produce 50,000 unique values. It can be used to provide a greater range with a little ingenuity. This packs 8 random bytes and unpack as a quad to produce a reasonable 64-bit rand that is still quicker than the MT:
Why this sad state persists in the MS CRT is because it seen as better to keep a seriously deficient rand function for trivial purposes and thus force users to seek out/write a better one for their particular serious purposes. That if they added (say) the MT, then people would either fall foul of or complain that it wasn't good enough for cryptographic purposes. And if they added a cryptographically-secure PRNG, then people would decry it as too slow for Monte-Carlo simulation purposes. Etc. Take that as you may. With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Seekers of Perl Wisdom
|
|