Skip to content

Instantly share code, notes, and snippets.

@andrearufo
Created September 18, 2014 22:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrearufo/9070df408fd978d5e020 to your computer and use it in GitHub Desktop.
Save andrearufo/9070df408fd978d5e020 to your computer and use it in GitHub Desktop.
Super simple Gaussian distribution with two dice
<pre>
<?php
$n = 10000;
$min = 1;
$max = 20;
$values = array();
for( $i=0; $i<$n; $i++ ):
$dado1 = rand($min, $max);
$dado2 = rand($min, $max);
$somma = $dado1 + $dado2;
array_push($values, $somma);
endfor;
print_r($values);
$counts = array();
for($v=($min*2); $v<=($max*2); $v++ ):
$counts[$v] = 0;
endfor;
foreach( $values as $item ):
$counts[$item]++;
endforeach;
print_r($counts);
?>
</pre>
<ol>
<?php for($v=1; $v<=($max*2)+1; $v++ ): ?>
<li style="
width: <?=$counts[$v]*2?>px;
background: #ccc;
margin-bottom: 2px;
font-family: monospace;
">
<?=$counts[$v]?>
</li>
<?php endfor ?>
</ol>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment