note 100236 added to function.rand

From: Date: Sun, 03 Oct 2010 16:26:52 +0000
Subject: note 100236 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-172909@lists.php.net to get a copy of this message
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. ---- Server IP: 192.41.42.26 Probable Submitter: 72.47.10.186 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/100236 Del: integrated -- https://master.php.net/note/delete/100236/integrated Del: useless -- https://master.php.net/note/delete/100236/useless Del: bad code -- https://master.php.net/note/delete/100236/bad+code Del: spam -- https://master.php.net/note/delete/100236/spam Del: non-english -- https://master.php.net/note/delete/100236/non-english Del: in docs -- https://master.php.net/note/delete/100236/in+docs Del: other reasons-- https://master.php.net/note/delete/100236 Reject -- https://master.php.net/note/reject/100236 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#172909) next »