Keep It Simple, Stupid | |
PerlMonks |
Re: how to get a 64bit random number with rand() ?by bliako (Monsignor) |
on Mar 22, 2018 at 14:55 UTC ( [id://1211529]=note: print w/replies, xml ) | Need Help?? |
Can't agree more with BrowserUk. Whatever you do always verify the statistical distribution of your method for producing random numbers. In order to do that you need to produce a large bunch of these random numbers and plot a histogram of their values or, much more accurate, run a test for verifying the distribution. Here is a test for a discrete distribution, e.g. dice numbers: https://stackoverflow.com/questions/21204733/a-better-chi-square-test-for-perl Perl's rand() will, in theory, produce random numbers drawn from a uniform distribution: all values from 0 to 1 have equal probability to appear. The histogram of such a distribution is more-or-less a flat line (the equal probabilities). Provided that you draw *a lot* of random numbers you will be approximating that. Now if you *add* two rand() values in order, for example, to get a 64-bit random value you will find that the histogram of the numbers you get is not a flat line anymore but resembling more of a bell-curve, the trademark of a Gaussian (aka Normal) distribution. I would love to play poker against a machine which uses this method ... Here is some code to demonstrate this:
Bottomline: I always wanted to ask Einsten to clarify whether "dice" in his famous "God does not play dice" is plurar or singular. I guess I will never know although maybe 60 years ago dice did have the singular of die. If God plays with a single dice his or her distributions will be Uniform (the flat lines). However, if God plays with two dice (and sums up the two rands) his/her distributions will be Gaussian (the bell shape) and that makes a lot of difference for the Universe. bliako
In Section
Seekers of Perl Wisdom
|
|