fork download
  1. <?php
  2.  
  3. $dice = 7;
  4.  
  5. $storage = array_fill($dice,$dice*6-$dice+1,0);
  6.  
  7. for ($i=1;$i<1000000;$i++) {
  8. $sum=0;
  9. for ($j=1;$j<=$dice;$j++) {
  10. $num=mt_rand(1,6);
  11. $sum+=$num;
  12. }
  13. $storage[$sum]++;
  14. }
  15.  
  16. foreach ($storage as $index => $number) {
  17.  
  18. echo str_pad($index,2,"0",STR_PAD_LEFT);
  19. echo "|";
  20. echo str_repeat("|", $number/1000);
  21.  
  22. echo"$number\n";
  23. }
  24.  
Success #stdin #stdout 3.95s 20520KB
stdin
Standard input is empty
stdout
07|4
08|21
09|103
10|298
11|728
12||1607
13||||3296
14||||||5972
15||||||||||9890
16||||||||||||||||15683
17||||||||||||||||||||||||23588
18|||||||||||||||||||||||||||||||||32375
19||||||||||||||||||||||||||||||||||||||||||||43374
20|||||||||||||||||||||||||||||||||||||||||||||||||||||||54133
21||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||65523
22|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||74702
23|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||82397
24|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||86210
25||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||85595
26||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||81868
27||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||75247
28||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||65662
29|||||||||||||||||||||||||||||||||||||||||||||||||||||||54557
30||||||||||||||||||||||||||||||||||||||||||||43354
31|||||||||||||||||||||||||||||||||32406
32||||||||||||||||||||||||23615
33||||||||||||||||15769
34|||||||||||10197
35||||||5840
36||||3264
37||1618
38|693
39|298
40|90
41|18
42|4