Bug #18557 Updated: array_rand() with mt_srand() not giving me random values
| From: | derick@php.net | Date: | Thu, 25 Jul 2002 12:50:58 +0000 |
| Subject: | Bug #18557 Updated: array_rand() with mt_srand() not giving me random values | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-15188@lists.php.net to get a copy of this message | ||
ID: 18557
Updated by: derick@php.net
Reported By: naintara@ndf.vsnl.net.in
-Status: Open
+Status: Closed
Bug Type: Arrays related
Operating System: Windows 2000 Professional Server
PHP Version: 4.2.1
New Comment:
Closing then
Previous Comments:
------------------------------------------------------------------------
[2002-07-25 08:49:17] naintara@ndf.vsnl.net.in
After installing the following:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
PHP 4.2.3-dev version the bug seems to be fixed.
Thanks so much for your time.
------------------------------------------------------------------------
[2002-07-25 05:17:35] edink@php.net
This should be fixed in this snapshot:
http://snaps.php.net/win32/php4-win32-STABLE-latest.zip
Could please see if this fixes your problem?
------------------------------------------------------------------------
[2002-07-25 05:06:22] naintara@ndf.vsnl.net.in
I tried with srand() too, it made no difference.
In fact, even after a full day, I am getting the same value I was
getting yesterday.
I'd like to add from my observation, the random values returned through
rand() value is not the problem, the problem is with the array_rand()
values returned.
------------------------------------------------------------------------
[2002-07-25 04:41:23] sniper@php.net
You should be calling srand() NOT mt_srand()..does this make any
difference? (actually it should not be even necessary anymore to call
that either since 4.2.0..)
------------------------------------------------------------------------
[2002-07-25 03:12:44] naintara@ndf.vsnl.net.in
I have an array of 26 characters. I want three random values from the
array, I use the following:
$rand_al = array_rand ($arralpha, 3);
Prob: I get the same characters each and every time.
What I am doing: First I seed the generator with
mt_srand ((double) microtime() * 1000000);
I fill my array $arralpha with values, and use the array_rand()
function to return me random indexes
$rand_al = array_rand ($arralpha, 3);
On echoing the values at those indexes, I got the same values each
time
Workaround: The way I am handling it right now is generating random
values using mt_rand(0,25)
and using those random values as the array subscripts. This method
gives me random values.
Additional Info: mt_getrandmax() returned 2147483647.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=18557&edit=1