Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > #37409 : rand and mt_rand BUG
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 2nd June 11:15
php-bugs
External User
 
Posts: 1
Default #37409 : rand and mt_rand BUG


From: Kazeuri at Gmail dot com
Operating system: SUSE 10
PHP version: 4.4.2
PHP Bug Type: Unknown/Other Function
Bug description: rand and mt_rand BUG

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 do***entation 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).

--
Edit bug report at http://bugs.php.net/?id=37409&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37409&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37409&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37409&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37409&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=37409&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37409&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37409&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37409&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37409&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37409&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=37409&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=37409&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37409&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37409&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37409&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37409&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37409&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37409&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37409&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37409&r=mysqlcfg
  Reply With Quote


  sponsored links


2 2nd June 11:15
External User
 
Posts: 1
Default #37409 : rand and mt_rand BUG


ID: 37409
Updated by: tony2001@php.net
Reported By: Kazeuri at Gmail dot com
-Status: Open
+Status: Feedback
-Bug Type: Unknown/Other Function
+Bug Type: Math related
Operating System: SUSE 10
PHP Version: 4.4.2
New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2006-05-11 15:44:25] 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 do***entation
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).


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=37409&edit=1
  Reply With Quote
3 2nd June 11:15
php-bugs
External User
 
Posts: 1
Default #37409 : rand and mt_rand BUG


From: Kazeuri at Gmail dot com
Operating system: SUSE 10
PHP version: 4.4.2
PHP Bug Type: Unknown/Other Function
Bug description: rand and mt_rand BUG

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 do***entation 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).

--
Edit bug report at http://bugs.php.net/?id=37409&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37409&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37409&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37409&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37409&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=37409&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37409&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37409&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37409&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37409&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37409&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=37409&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=37409&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37409&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37409&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37409&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37409&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37409&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37409&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37409&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37409&r=mysqlcfg
  Reply With Quote
4 2nd June 11:15
External User
 
Posts: 1
Default #37409 : rand and mt_rand BUG


ID: 37409
Updated by: tony2001@php.net
Reported By: Kazeuri at Gmail dot com
-Status: Open
+Status: Feedback
-Bug Type: Unknown/Other Function
+Bug Type: Math related
Operating System: SUSE 10
PHP Version: 4.4.2
New Comment:

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.


Previous Comments:
------------------------------------------------------------------------

[2006-05-11 15:44:25] 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 do***entation
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).


------------------------------------------------------------------------


--
Edit this bug report at http://bugs.php.net/?id=37409&edit=1
  Reply With Quote


  sponsored links


Reply


Thread Tools
Display Modes




Copyright 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666