#26949 [Fbk]: rand(min,max) always returns min when zts enabled
| From: | sniper@php.net | Date: | Sun, 18 Jan 2004 14:36:42 +0000 |
| Subject: | #26949 [Fbk]: rand(min,max) always returns min when zts enabled | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-53520@lists.php.net to get a copy of this message | ||
ID: 26949
Updated by: sniper@php.net
Reported By: alucard at vitriolic dot org
Status: Feedback
Bug Type: Math related
Operating System: Solaris 9
PHP Version: 4CVS-2004-01-18
New Comment:
Also, what does this output (in zts and in non-zts mode):
# sapi/cli/php 'echo getrandmax();'
Previous Comments:
------------------------------------------------------------------------
[2004-01-18 09:35:02] sniper@php.net
Try adding 'srand();' call there:
# sapi/cli/php -r 'srand(); echo rand(0,100),"\n";'
Does this work better?
(Note: I can not reproduce this within Linux)
------------------------------------------------------------------------
[2004-01-18 02:04:50] alucard at vitriolic dot org
Same results:
# rm config.cache
config.cache: No such file or directory
# ./configure --disable-all --disable-cgi --enable-experimental-zts
# make clean && make
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
29622
0
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
6807
0
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
2050
0
# sapi/cli/php -v
PHP 4.3.5RC2-dev (cli) (built: Jan 18 2004 00:52:22)
Without zts enabled, the results are:
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
2121634529
48
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
1303411959
20
------------------------------------------------------------------------
[2004-01-17 20:20:48] sniper@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php4-STABLE-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
------------------------------------------------------------------------
[2004-01-17 17:34:41] alucard at vitriolic dot org
Description:
------------
Bug #24909 is still an issue with latest build and Solaris 9.
When rand() is called with no arguments, it operates as expected. When
rand(min,max) is called, it always returns value 'min'.
This problem only occurs when ZTS is enabled. When it's not, both
calls to rand() work as expected, though the value ranges are
completely different.
To demonstrate:
# uname -a
SunOS XXXXXX 5.9 Generic_112233-08 sun4u sparc SUNW,Ultra-Enterprise
# rm config.cache
# ./configure --disable-all --disable-cgi --enable-experimental-zts
# make clean && make
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
28909
0
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
21885
0
# rm config.cache
# ./configure --disable-all --disable-cgi
# make clean && make
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
1116498057
87
# sapi/cli/php -r 'echo rand(),"\n"; echo rand(0,100),"\n";'
102735333
95
Note that with zts enabled, the rand() values are much smaller, and
rand(min,max) always returns min. Without it, rand values are much
larger, and rand(min,max) operates as expected.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=26949&edit=1