Created
June 12, 2015 04:05
-
-
Save trepmal/d26d1000a9665e8525aa to your computer and use it in GitHub Desktop.
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
<?php | |
// testing how often a number in a given range will appear over many iterations | |
$max = 10; // how big of a range? ( 1 thru $max ) | |
$iterations = 100000; // how many iterations | |
// set up an array for keeping tally | |
$totals = array_fill( 1, $max, 0 ); | |
for ( $i = 1; $i <= $iterations; $i++ ) { | |
$totals[ rand( 1, $max ) ]++; | |
} | |
echo '<pre>'; | |
foreach ( $totals as $num => $count ) { | |
$percent = $count/$iterations*100; | |
echo "$num: $percent%\n"; | |
} | |
echo '</pre>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment