#26381 [Opn->Fbk]: rand() without srand() doesn't work

From: Date: Tue, 25 Nov 2003 09:24:33 +0000
Subject: #26381 [Opn->Fbk]: rand() without srand() doesn't work
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-50968@lists.php.net to get a copy of this message
ID: 26381 Updated by: sniper@php.net Reported By: spam at vrana dot cz -Status: Open +Status: Feedback Bug Type: Math related Operating System: Windows XP PHP Version: 4.3.3 New Comment: 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 Works fine for me within Windows XP, within Apache and CLI. Previous Comments: ------------------------------------------------------------------------ [2003-11-25 03:38:43] spam at vrana dot cz So this is a documentation problem because in rand() function documentation is written: As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically. Anyway, I think it's not a documentation bug because in other environments it works as stated. ------------------------------------------------------------------------ [2003-11-24 20:01:53] iliaa@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php if you want trully random numbers you MUST call srand before rand(). ------------------------------------------------------------------------ [2003-11-24 08:21:33] spam at vrana dot cz Description: ------------ Function rand() without setting random seed by srand() returns always the same value. It doesn't work only on Windows PHP-CLI. As Windows Apache module and also on Linux PHP-CLI it works as it should. Reproduce code: --------------- echo rand(); Expected result: ---------------- (random value) Actual result: -------------- 24849 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=26381&edit=1

« previous php.bugs (#50968) next »