From:             bugs at nazarenko dot net
Operating system: Linux, Solaris
PHP version:      5CVS-2007-08-28 (snap)
PHP Bug Type:     Math related
Bug description:  rand() and mt_rand() return same values from forked processes

Description:
------------
Using CLI, if more than 1 process is forked with pcntl_fork() both
functions mt_rand() and rand() return same values in all child processes.

This only happens when there was a call to mt_rand()/rand() in the parent
process before forking. 

Reproduce code:
---------------
Compiled latest available snapshot under Solaris 10 and SuSE Linux 10.1
with the following configure options:

--disable-all --disable-cgi --enable-pcntl --disable-ipv6


The test script is the following:

<?php

echo mt_rand(0,255)."\n";   # comment this line out to see difference

for ($i=0; $i<3; $i++)
{
        if (pcntl_fork() == 0)
        {
                die(mt_rand(0,255)."\n");
        }
}

?>


Expected result:
----------------
Expected result is 4 random numbers generated by 4 different Unix
processes (1 parent and 3 children).

Actual result:
--------------
The actual result (both on Solaris and Linux) is that all 3 numbers
generated by the children are the same.

Now comment out the first echo command belonging to the parent process and
the result is 3 random numbers generated by children.

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

Reply via email to