Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: is rand random enough to simulate dice rolls?

by afoken (Chancellor)
on Jan 03, 2021 at 14:46 UTC ( [id://11126202]=note: print w/replies, xml ) Need Help??


in reply to is rand random enough to simulate dice rolls?

While the above seems to be ok on my platform, can I expect the same result on every platform? and for every perl version around the world?

At least old perls for Windows had a very limited PRNG, with an interval of only 2^14 (?). I've no idea how evenly distributed its output is/was. So, the quality of rand() differs from platform to platform and may also change with the perl version.

Should I repeat the check 100 times to have an average of averages?

Averaging averages won't help. After all, you just sum up n*m numbers and divide by n*m - either in n steps or all at once. Using the median of n averages might help.

Update:

See also Random numbers are not random enough on Windows and https://www.effectiveperlprogramming.com/2014/06/perl-5-20-uses-its-own-random-number-generator/.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
  • Comment on Re: is rand random enough to simulate dice rolls?

Replies are listed 'Best First'.
Re^2: is rand random enough to simulate dice rolls?
by LanX (Saint) on Jan 03, 2021 at 16:33 UTC
    > At least old perls for Windows had a very limited PRNG, with an interval of only 2^14 (?).

    Having an interval of 2**14 ~= 16_000 means the sequence repeats.

    > I've no idea how evenly distributed its output is/was.

    By definition it must hit the average 3.5 exactly after 2**14 runs.°

    IMHO 10000 runs for a margin of ± 0.2 is a safe bet. ²

    If this test fails, something must be done.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    °) modulo rounding errors with Perl floats

    ²) that's more than 3% of the interval!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11126202]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-24 19:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found