Created
October 9, 2012 16:30
-
-
Save darookee/3859897 to your computer and use it in GitHub Desktop.
generates better randomness
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 | |
function generateRandomness( $fraction = 0.025 ) { | |
return - ( log( 1.0 - (float) ( mt_rand() / ( mt_getrandmax() + 1 ) ) ) / $fraction ); | |
} | |
for( $x=0; $x<=10; $x++ ) { | |
$rands = 100000; | |
for( $i=0; $i<=$rands; $i++ ) | |
$rand += generateRandomness( 1/40 ); | |
echo( $x . ': ' . ( $rand / $rands ) . "\n" ); | |
$rand = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment