php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37409 rand and mt_rand BUG
Submitted: 2006-05-11 15:44 UTC Modified: 2006-05-19 01:00 UTC
From: Kazeuri at Gmail dot com Assigned:
Status: No Feedback Package: Math related
PHP Version: 4.4.2 OS: SUSE 10
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Kazeuri at Gmail dot com
New email:
PHP Version: OS:

 

 [2006-05-11 15:44 UTC] Kazeuri at Gmail dot com
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).

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-11 15:53 UTC] tony2001@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.

Please provide a reproduce code without use of image*() functions.
 [2006-05-19 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 01 17:01:32 2024 UTC