Skip to content

Instantly share code, notes, and snippets.

@ajakubek
Created February 21, 2013 01:59
Show Gist options
  • Save ajakubek/5001330 to your computer and use it in GitHub Desktop.
Save ajakubek/5001330 to your computer and use it in GitHub Desktop.
PHP fails at uniform distribution
<?php
const RAND_MULTIPLE = 4;
$histogram = array_fill(0, getrandmax() * RAND_MULTIPLE, 0);
for ($i = 0; $i < 10000000; ++$i)
{
$rnd = rand(0, getrandmax() * RAND_MULTIPLE);
++$histogram[$rnd];
}
for ($i = 0; $i < count($histogram); ++$i)
echo "$i, $histogram[$i]\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment