note 100236 deleted from function.rand by danbrown

From: Date: Sun, 03 Oct 2010 22:16:34 +0000
Subject: note 100236 deleted from function.rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-172917@lists.php.net to get a copy of this message
Note Submitter: charlie at brown dot org ---- random dot org/analysis/ has a side-by-side graphic of a true random number generator and PHP's (pseudo-random) rand(). It shows strong vertical patterns(bad). I did my own to see how bad it is but I can't reproduce their results. Here's my code. It looks as good as their true random graphic: <?php define('WIDTH', 512); define('HEIGHT', WIDTH); $gd = imagecreatetruecolor(WIDTH, HEIGHT); $white = imagecolorallocate($gd, 255, 255, 255); for($col=0; $col<WIDTH; $col++) { for($row=0; $row<HEIGHT; $row++) { $r = (int)rand(0,1); if($r) { imagesetpixel($gd, $col, $row, $white); } } } header('Content-Type: image/png'); imagepng($gd); ?> I tested on a linux server so maybe it's just PHP in Windows that has a problem.

« previous php.notes (#172917) next »