Skip to content

Instantly share code, notes, and snippets.

@darookee
Created October 9, 2012 16:30
Show Gist options
  • Save darookee/3859897 to your computer and use it in GitHub Desktop.
Save darookee/3859897 to your computer and use it in GitHub Desktop.
generates better randomness
<?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