in reply to Re: is rand random enough to simulate dice rolls?
in thread is rand random enough to simulate dice rolls?

Fantastic kcott,

Here the win32 version of the oneliner, with added info about perl and OS:

perl -e "my $iters = 100_000; my $runs = 6; for my $sides (qw{1 2 3 4 +6 8 10 20 100}) { printf '%-5s', qq(D$sides:); for (1 ..$runs) { my $ +tot = 0; for (1 .. $iters) { $tot += int(rand $sides)+1; } print ' ', + $tot/$iters; } print qq(\n); } print qq(Perl $^V $^O\n)"

And here are mine test results, all tests done in win10 and various strawberry protable:

# perl 5.26 64bit D1: 1 1 1 1 1 1 D2: 1.49728 1.49979 1.49854 1.49977 1.50298 1.49972 D3: 2.00109 1.99922 1.99705 2.00131 2.00066 1.99933 D4: 2.49997 2.49926 2.49824 2.50176 2.49721 2.50158 D6: 3.49789 3.4945 3.50307 3.49706 3.49873 3.49967 D8: 4.50906 4.50074 4.49878 4.49863 4.49699 4.49534 D10: 5.50115 5.49664 5.49682 5.4829 5.48539 5.50885 D20: 10.48781 10.51603 10.53692 10.48499 10.4977 10.47859 D100: 50.43999 50.51722 50.4861 50.56783 50.49071 50.46732 Perl v5.26.0 MSWin32 # perl 5.20 64bit D1: 1 1 1 1 1 1 D2: 1.50002 1.50098 1.50027 1.50081 1.50254 1.49815 D3: 1.9922 1.99659 1.99707 1.99924 1.99908 1.99999 D4: 2.49771 2.49966 2.50482 2.49946 2.49785 2.4987 D6: 3.50342 3.50138 3.4978 3.49477 3.50353 3.50182 D8: 4.49888 4.50591 4.50095 4.48605 4.49364 4.49382 D10: 5.50832 5.49959 5.49786 5.50018 5.49388 5.50274 D20: 10.49467 10.5032 10.48564 10.52528 10.45654 10.49782 D100: 50.60325 50.57722 50.53147 50.46864 50.53958 50.30884 Perl v5.20.3 MSWin32 #perl 5.22 64bit D1: 1 1 1 1 1 1 D2: 1.4988 1.50017 1.50026 1.49912 1.50178 1.49942 D3: 2.00206 2.0024 2.00078 2.00151 1.99834 2.00194 D4: 2.50002 2.49894 2.49548 2.49825 2.50101 2.49567 D6: 3.49631 3.49881 3.49596 3.50121 3.50469 3.50556 D8: 4.50097 4.49576 4.50741 4.49163 4.50218 4.50035 D10: 5.48775 5.49495 5.49863 5.51452 5.50426 5.49525 D20: 10.49001 10.51559 10.46902 10.50395 10.47399 10.51619 D100: 50.4696 50.58086 50.56925 50.53794 50.45582 50.55695 Perl v5.22.3 MSWin32 #perl 5.24 64bit D1: 1 1 1 1 1 1 D2: 1.50176 1.50093 1.50375 1.49886 1.49829 1.4978 D3: 1.99889 1.99722 2.00216 2.00232 1.99973 2.0025 D4: 2.50295 2.50345 2.50489 2.4964 2.49571 2.49994 D6: 3.50793 3.49375 3.49834 3.50353 3.49543 3.50472 D8: 4.48382 4.50156 4.50724 4.49537 4.50094 4.50467 D10: 5.50561 5.49698 5.50331 5.50191 5.51183 5.49333 D20: 10.51188 10.49523 10.51253 10.52995 10.52965 10.50506 D100: 50.4417 50.37094 50.4741 50.62746 50.53223 50.55502 Perl v5.24.2 MSWin32 #perl 5.26 64bit D1: 1 1 1 1 1 1 D2: 1.49995 1.50071 1.49846 1.49906 1.49984 1.49977 D3: 2.00044 1.99638 1.9986 2.00209 2.00057 2.00021 D4: 2.50587 2.50951 2.49899 2.5003 2.50401 2.49556 D6: 3.49642 3.49724 3.50929 3.49369 3.49324 3.50481 D8: 4.48084 4.49379 4.50828 4.50079 4.50653 4.50257 D10: 5.49304 5.50007 5.51128 5.51153 5.49389 5.49713 D20: 10.46065 10.49741 10.49662 10.50199 10.5104 10.50549 D100: 50.48183 50.38416 50.41408 50.47176 50.30296 50.53482 Perl v5.26.0 MSWin32 #perl 5.26 64bit PDL version D1: 1 1 1 1 1 1 D2: 1.49836 1.50338 1.4989 1.50025 1.49961 1.49982 D3: 1.9985 2.00365 2.00221 1.99604 2.00141 1.99762 D4: 2.5029 2.50257 2.49807 2.5005 2.49348 2.49663 D6: 3.50266 3.50063 3.50627 3.48774 3.5096 3.50361 D8: 4.504 4.48456 4.49345 4.50077 4.50083 4.50001 D10: 5.50843 5.50186 5.49619 5.50336 5.49785 5.50342 D20: 10.50045 10.44466 10.5242 10.50923 10.50356 10.51332 D100: 50.39945 50.51811 50.47581 50.44648 50.4911 50.47012 Perl v5.26.2 MSWin32

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: is rand random enough to simulate dice rolls?
by etj (Priest) on Apr 18, 2022 at 19:44 UTC
    I saw this post while looking up old PDL nodes, and you mentioned PDL there. PDL as of 2.062 uses a "better" (and thread-safe, for potential massive performance gainz) pseudo-random number generator, xoroshiro256plus (see link for thorough statistical analysis of it and competing algorithms) rather than the often-weak and usually non-thread-safe system rand() that Perl uses.
Re^3: is rand random enough to simulate dice rolls?
by shmem (Chancellor) on Jan 04, 2021 at 08:55 UTC
    And here are mine test results, all tests done in win10 and various strawberry protable:

    And your conclusion is? It looks to me like all those perls are pretty well behaved, including my old ones (see above).

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
      Hello shmem,

      > And your conclusion is? It looks to me like all those perls are pretty well behaved, including my old ones

      Yes it seems so. My conclusion was in Re^2: is rand random enough to simulate dice rolls?: as haukex and other said is unwise to break a test for something related to a core function which might have problems in preistoric installations. A big warning, as above, is more than nothing in case of test failure.

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.