PHP True Random 小試驗


環境: Mac OS X 10.6.8
PHP: PHP 5.3.1
結果:
得出的圖片看得出來應該算是 True Random 來的
但舊版本的 PHP 好像得不到這種效果?(註: 參考中提及)

1
2
3
4
5
6
7
8
9
10
11
12
header("Content-type: image/png");
$im = imagecreatetruecolor(512, 512) or die("Cannot Initialize new GD image stream");
$white = imagecolorallocate($im, 255, 255, 255);
for ($y=0; $y<512; $y++) {
for ($x=0; $x<512; $x++) {
if (rand(0,1) === 1) {
imagesetpixel($im, $x, $y, $white);
}
}
}
imagepng($im);
imagedestroy($im);

參考: http://www.boallen.com/random-numbers.html