From:             bassfranky at hotmail dot com
Operating system: Linux
PHP version:      Irrelevant
PHP Bug Type:     *Math Functions
Bug description:  Pb with functions rand() srand() and mt_rand()

Description:
------------
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)
{
        srand();
        $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 !


-- 
Edit bug report at http://bugs.php.net/?id=29507&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=29507&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=29507&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=29507&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=29507&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=29507&r=needtrace
Need Reproduce Script:      http://bugs.php.net/fix.php?id=29507&r=needscript
Try newer version:          http://bugs.php.net/fix.php?id=29507&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=29507&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=29507&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=29507&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=29507&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=29507&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=29507&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=29507&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=29507&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=29507&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=29507&r=float

Reply via email to