ID: 42465 Updated by: [EMAIL PROTECTED] Reported By: bugs at nazarenko dot net -Status: Open +Status: Bogus Bug Type: Math related Operating System: Linux, Solaris PHP Version: 5CVS-2007-08-28 (snap) New Comment:
http://php.net/mt_srand http://php.net/srand Previous Comments: ------------------------------------------------------------------------ [2007-08-28 19:31:32] bugs at nazarenko dot net 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 this bug report at http://bugs.php.net/?id=42465&edit=1