Last active
April 29, 2017 17:19
-
-
Save mixdev/49e9a672571f9309676aabd1c2134565 to your computer and use it in GitHub Desktop.
Simple Monte Carlo Simulation of rolling two regular dice. Shows visual results in shell. Shows clear central tendency. The problem stated here http://www.goldsim.com/Web/Introduction/Probabilistic/MonteCarlo/
This file contains hidden or 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
<?php | |
$simulations = 10000; | |
$dicesides = 6; | |
$count = Array(); | |
for($i=0; $i<$simulations; $i++) { | |
$x = mt_rand(1,$dicesides); | |
$y = mt_rand(1,$dicesides); | |
@$count[$x+$y]++; | |
} | |
for($i=2;$i<= 2 * $dicesides;$i++){ | |
$prob = $count[$i]/$simulations; | |
$size=str_pad('',$prob*200,'='); | |
echo "P($i)\t=\t". $prob ."\t". $size ."\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment