Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: is rand random enough to simulate dice rolls?

by shmem (Chancellor)
on Jan 04, 2021 at 06:59 UTC ( #11126259=note: print w/replies, xml ) Need Help??


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

If you could get a few people to post results for a variety of platforms, installations and Perl versions that they might have available, you may get something approaching a reasonable answer to your "every platform ... every version" question.

Well, here's an old platform and an old version ;-)

canis [shmem] /home/shmem > time perl -e 'my $iters = 100_000; my $run +s = 6; for my $sides (qw{1 2 3 4 6 8 10 20 100}) { printf "%-5s", "D$ +sides:"; for (1 .. $runs) { my $tot = 0; for (1 .. $iters) { $tot += +int(rand $sides)+1; } print " ", $tot/$iters; } print "\n"; } ' D1: 1 1 1 1 1 1 D2: 1.5017 1.50273 1.49927 1.50004 1.50069 1.50234 D3: 2.00005 2.0013 1.99667 2.00228 2.00141 2.0018 D4: 2.49651 2.49254 2.50251 2.5008 2.49389 2.50032 D6: 3.4947 3.49803 3.4938 3.50231 3.50249 3.49613 D8: 4.50561 4.51195 4.51012 4.50395 4.4961 4.50096 D10: 5.52471 5.50722 5.50845 5.4933 5.4983 5.49319 D20: 10.51722 10.48846 10.52023 10.50762 10.48594 10.52206 D100: 50.43492 50.46292 50.4675 50.66063 50.35462 50.46591 293.510u 0.450s 4:54.97 99.6% 0+1599k 4+7io 1pf+0w canis [shmem] /home/shmem > uname -a SunOS canis 4.1.4 5 sun4m canis [shmem] /home/shmem > perl -v This is perl, version 5.004 Copyright 1987-1997, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5.0 source +kit.

SPARCstation voyager, cpu = SUNW,S240. Sorry, no PDP-11 available, and the Atari is out of order.

Update: looks like perl4 is significantly slower. But the numbers look right.

canis [shmem] /home/shmem > time perl4 -e '$iters = 100_000; $runs = 6 +; for $sides (1,2,3,4,6,8,10,20,100) { printf "%-5s", "D$sides:"; for + (1 .. $runs) { $tot = 0; for (1 .. $iters) { $tot += int(rand $sides +)+1; } print " ", $tot/$iters; } print "\n"; }' D1: 1 1 1 1 1 1 D2: 1.4976199999999999513 1.4995000000000000551 1.500839999999999951 +9 1.5009200000000000319 1.4983500000000000707 1.4992000000000000881 D3: 1.9988500000000000156 2.0010099999999999554 1.997360000000000024 +3 1.9947699999999999321 2.0022500000000000853 1.9987600000000000922 D4: 2.4961099999999998289 2.5017000000000000348 2.501459999999999794 +8 2.4986999999999999211 2.4970900000000000318 2.5005099999999997884 D6: 3.50016000000000016 3.4905300000000001326 3.5027200000000000557 +3.4986999999999999211 3.4940500000000001002 3.4981499999999998707 D8: 4.5008200000000000429 4.4963499999999996248 4.499399999999999622 + 4.505130000000000301 4.500880000000000436 4.4966600000000003234 D10: 5.5046299999999996899 5.4901400000000002422 5.493229999999999613 +2 5.4982899999999998997 5.4878000000000000114 5.481379999999999697 D20: 10.478590000000000515 10.511730000000000018 10.48712000000000088 +6 10.511749999999999261 10.520690000000000097 10.513320000000000221 D100: 50.332399999999999807 50.534730000000003258 50.68713999999999941 +8 50.558239999999997849 50.449489999999997281 50.479340000000000543 473.690u 154.350s 26:25.22 39.6% 0+4164k 0+7io 39159pf+0w canis [shmem] /home/shmem > perl4 -v This is perl, version 4.0 $RCSfile: perl.c,v $$Revision: 4.0.1.4 $$Date: 91/06/10 01:23:07 $ Patch level: 10 Copyright (c) 1989, 1990, 1991, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 4.0 source +kit.
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2021-02-28 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?