Bug #18557 Updated: array_rand() with mt_srand() not giving me random values

From: Date: Thu, 25 Jul 2002 08:41:23 +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-15140@lists.php.net to get a copy of this message
ID: 18557 Updated by: sniper@php.net Reported By: naintara@ndf.vsnl.net.in -Status: Open +Status: Feedback Bug Type: Arrays related Operating System: Windows 2000 Professional Server PHP Version: 4.2.1 New Comment: 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..) Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#15140) next »