Created
September 18, 2014 22:10
-
-
Save andrearufo/9070df408fd978d5e020 to your computer and use it in GitHub Desktop.
Super simple Gaussian distribution with two dice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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