Bug #18557: array_rand() with mt_srand() not giving me random values
| From: | naintara at ndf dot vsnl dot net dot in | Date: | Thu, 25 Jul 2002 07:12:44 +0000 |
| Subject: | Bug #18557: array_rand() with mt_srand() not giving me random values | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-15127@lists.php.net to get a copy of this message | ||
From: naintara@ndf.vsnl.net.in
Operating system: Windows 2000 Professional Server
PHP version: 4.2.1
PHP Bug Type: Arrays related
Bug description: array_rand() with mt_srand() not giving me random values
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 bug report at http://bugs.php.net/?id=18557&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=18557&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=18557&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=18557&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=18557&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=18557&r=support
Expected behavior: http://bugs.php.net/fix.php?id=18557&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=18557&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=18557&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=18557&r=globals