Kudose wrote:
srand((float)microtime() * 1000000);
I take it all back: in that case the number of possible hashes is 1,000,000, because that's how many possible random seeds there are from that generator (you do know that [man]srand[/man] isn't required any more?)
Using the default seeding mechanism would help, but not on Windows. Windows's rand() is already limited to 15 bits, which means that all seeds (and all output values) are limited to between 0 and 32767 inclusive. It's a linear-congruential generator, too; there's effectively only one sequence, from which you have a choice of 32768 different starting points.
$t = array_fill(0, 32768, 0);
for($i=0; $i<32768; ++$i)
{
$t[rand()]++;
}
echo join("", $t);
Being linear-congruential, if you know the output at one point, you can determine future points. 3611 is always followed by 27576 is always followed by 7569, and what srand() does is let you pick your starting point.
srand(42); echo rand(),"\t",rand(),"\n";
srand(3611); echo rand(),"\t",rand(),"\n";
srand(27576); echo rand(),"\t",rand(),"\n";
$im = imagecreate(32768>>4, 32768>>4);
$yellow = imagecolorallocate($im, 255,255,0);
$black = imagecolorallocate($im, 0,0,0);
imagefilledrectangle($im, 0,0,32768>>4, 32768>>4, $black);
$y = 0;
for($t=0; $t<100000; ++$t)
{
$x = rand();
imagesetpixel($im, $x>>4, $y>>4, $yellow);
$y = $x;
}
imagepng($im, 'phaseplot.png');
The Mersenne Twister, on the other hand, has 2,147,483,647 different starting values and hence at most that many different sequences. The Mersenne Twister has a much longer period before it starts repeating because it maintains a buffer of previous values and uses those when generating the next; but PHP does not support any initialisation beyond a single 31-bit value. But because of that buffer, just knowing the value at one point is insufficient to predict the rest of the sequence.
$im = imagecreate(32768>>4, 32768>>4);
$yellow = imagecolorallocate($im, 255,255,0);
$black = imagecolorallocate($im, 0,0,0);
imagefilledrectangle($im, 0,0,32768>>4, 32768>>4, $black);
$y = 0;
for($t=0; $t<100000; ++$t)
{
$x = mt_rand();
imagesetpixel($im, $x>>20, $y>>20, $yellow);
$y = $x;
}
imagepng($im, 'mt_phaseplot.png');