|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-05-11 15:53 UTC] tony2001@php.net
[2006-05-19 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 08:00:01 2025 UTC |
Description: ------------ rand and mt_rand (which, no longer need to be seeded...) get stuck on the same "result" after a certain number of generations. I am unsure exactly why this is, and PLEASE, read in to this, its very easy at first to view this as a mistake, but according to all the documentation I have read, this should NOT occur. Reproduce code: --------------- header("Content-type: image/png"); $stext = "some text"; $x = 800; $y = 600; $im = @imagecreate($x, $y) or die("Cannot Initialize new GD image stream"); $background_color = imagecolorallocate($im, 0, 0, 0); $stnum = 0; while ($stnum <= 125){ $stize = rand(0,5); $xl = rand(0,800); $yl = rand(0,600); $text_color = imagecolorallocate($im, mt_rand(0,255), mt_rand(0,255), mt_rand(0,255)); imagestring($im, $stize, $xl, $yl, $stext, $text_color); $stnum += 1; } imagepng($im); imagedestroy($im); Expected result: ---------------- An image with randomly generated text all over it in various places (random). Actual result: -------------- This works fine, for about 50 results or so, and then somehow, ALL THREE rand functions that contribute to the text color get "stuck" and one particular color begins to dominate (which changes randomly each time it is generated).