|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29507 Pb with functions rand() srand() and mt_rand()
Submitted: 2004-08-03 16:38 UTC Modified: 2004-09-19 01:00 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: bassfranky at hotmail dot com Assigned:
Status: No Feedback Package: *Math Functions
PHP Version: Irrelevant OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: bassfranky at hotmail dot com
New email:
PHP Version: OS:


 [2004-08-03 16:38 UTC] bassfranky at hotmail dot com
I use rand(min, max) in a php script in a web page that is working pretty well.
But I also use it when this page open another (small) window
with another page that call the function rand() too.

This is working pretty well except when I reload the parent window and open again the small one, then the rand() function will return exactly the latest number !!!
Idem with srand() mt_rand()

For exemple on my parent window I click on my button "new"
this will open the small window and generate 5
I click again on "new" this will close and then reopen the small window and generate 8
etc . . . 
and then if I click on new and it'll open the small window
and generate for exemple 6
after that I reload the parent window and click again on "new" I will get a 6 again
After that if I click again on "new" it 'll be another one but if I reload the parent again, I'll definitely get a 6 again, and so on . . .

Reproduce code:
$nb = mysql_num_rows($resultMorceau);
if ($nob > 0)
	$hasard = mt_rand(0 , $nb-1);
        echo hasard;

Expected result:
I'd like to get a random number even if I reload my parent window frame !


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-11 14:30 UTC]
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 avoid embedding huge scripts into the report.

Use a better seed or provide a reproduce script.
 [2004-09-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-2022 The PHP Group
All rights reserved.
Last updated: Mon Jun 27 12:05:46 2022 UTC