posted by [identity profile] pete stevens at 10:36pm on 19/11/2013
30

source,

#!/usr/bin/perl

my $tests = 16384;
my @trials;
for (my $i = 0; $i < $tests; $i++) {
my $trials = 0;
my @oct = ( 1,1,1,0,0,0,0,0);
while ((eval join '+', @oct) != 8) {
$oct[int(rand() * 8)] = 1; $trials++;
}
$trials[$trials]++;
}
my $c = 0;
for (my $i = 0; $i < 50; $i++) {
if (defined($trials[$i])) { $c += $trials[$i]/$tests; }
print "$i : " . $trials[$i] . "(" . $trials[$i]/$tests . ") - " . $c . "\n";

}

Cumulative probability distribution

# ./oct.pl
0 : (0) - 0
1 : (0) - 0
2 : (0) - 0
3 : (0) - 0
4 : (0) - 0
5 : 47(0.00286865234375) - 0.00286865234375
6 : 180(0.010986328125) - 0.01385498046875
7 : 350(0.0213623046875) - 0.03521728515625
8 : 545(0.03326416015625) - 0.0684814453125
9 : 729(0.04449462890625) - 0.11297607421875
10 : 840(0.05126953125) - 0.16424560546875
11 : 891(0.05438232421875) - 0.2186279296875
12 : 914(0.0557861328125) - 0.2744140625
13 : 952(0.05810546875) - 0.33251953125
14 : 929(0.05670166015625) - 0.38922119140625
15 : 913(0.05572509765625) - 0.4449462890625
16 : 870(0.0531005859375) - 0.498046875
17 : 791(0.04827880859375) - 0.54632568359375
18 : 800(0.048828125) - 0.59515380859375
19 : 744(0.04541015625) - 0.64056396484375
20 : 642(0.0391845703125) - 0.67974853515625
21 : 633(0.03863525390625) - 0.7183837890625
22 : 521(0.03179931640625) - 0.75018310546875
23 : 459(0.02801513671875) - 0.7781982421875
24 : 387(0.02362060546875) - 0.80181884765625
25 : 370(0.0225830078125) - 0.82440185546875
26 : 361(0.02203369140625) - 0.846435546875
27 : 331(0.02020263671875) - 0.86663818359375
28 : 263(0.01605224609375) - 0.8826904296875
29 : 228(0.013916015625) - 0.8966064453125
30 : 197(0.01202392578125) - 0.90863037109375
31 : 187(0.01141357421875) - 0.9200439453125
32 : 147(0.00897216796875) - 0.92901611328125
33 : 165(0.01007080078125) - 0.9390869140625
34 : 102(0.0062255859375) - 0.9453125
35 : 98(0.0059814453125) - 0.9512939453125
36 : 102(0.0062255859375) - 0.95751953125
37 : 76(0.004638671875) - 0.962158203125
38 : 85(0.00518798828125) - 0.96734619140625
39 : 72(0.00439453125) - 0.97174072265625
40 : 60(0.003662109375) - 0.97540283203125
41 : 53(0.00323486328125) - 0.9786376953125
42 : 41(0.00250244140625) - 0.98114013671875
43 : 47(0.00286865234375) - 0.9840087890625
44 : 33(0.00201416015625) - 0.98602294921875
45 : 30(0.0018310546875) - 0.98785400390625
46 : 25(0.00152587890625) - 0.9893798828125
47 : 25(0.00152587890625) - 0.99090576171875
48 : 24(0.00146484375) - 0.99237060546875
49 : 23(0.00140380859375) - 0.9937744140625

Reply

From:
Anonymous( )Anonymous This account has disabled anonymous posting.
OpenID( )OpenID You can comment on this post while signed in with an account from many other sites, once you have confirmed your email address. Sign in using OpenID.
User
Account name:
Password:
If you don't have an account you can create one now.
Subject:
HTML doesn't work in the subject.

Message:

 
Notice: This account is set to log the IP addresses of everyone who comments.
Links will be displayed as unclickable URLs to help prevent spam.

May

SunMonTueWedThuFriSat
  1
 
2 3
 
4
 
5
 
6
 
7
 
8
 
9
 
10
 
11
 
12
 
13
 
14
 
15
 
16
 
17
 
18
 
19
 
20
 
21
 
22
 
23
 
24
 
25
 
26
 
27
 
28
 
29
 
30
 
31