Re: Bug #12455 Updated: Srand and shuffle give odd results

From: Date: Mon, 30 Jul 2001 08:06:26 +0000
Subject: Re: Bug #12455 Updated: Srand and shuffle give odd results
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-61477@lists.php.net to get a copy of this message
UNSUBSCRIBE ME PLEASE!!!!!!!!!!!!!! rasmus@php.net schrieb: > ID: 12455 > Updated by: rasmus > Reported By: sulka@sulake.com > Status: Open > Bug Type: *Math Functions > Operating System: SunOS 5.8 (Solaris) > PHP Version: 4.0.4pl1 > New Comment: > > I don't think I understand what the problem is here. I tested your code with the > following: > > <? > function pwd() { > $password = ""; > $array = > array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',0,1,2,4,5,6,7,8,9); > srand ((double)microtime()*1000000); > shuffle(&$array); > for ($i=0; $i<6; $i++) { $password .= $array[$i]; } > return $password; > } > > $i=0; > while($i<500) { > $password = pwd(); > $a[$password] = $password; > $i++; > } > echo count($a); > ?> > > This always returns 500 which means that 500 unique passwords were always created. > > Previous Comments: > ------------------------------------------------------------------------ > > [2001-07-29 05:51:30] sulka@sulake.com > > I'm using the following code to create random strings > (passwords): > > $password = ""; > $array = > > array('a','b','c','d','e','f','g','h','i','j','k','l','m',' > > n','o','p','q','r','s','t','u','v','w','x','y','z',0,1,2,4, > 5,6,7,8,9); > srand ((double)microtime()*1000000); > shuffle(&$array); > for ($i=0; $i<6; $i++) { $password .= $array[$i]; } > > Now, for some reason this seems to return only five > different values ever on the Solaris machine I'm running > the code on. And I'm not checking on the same run of the > script, this is based on accessing page with the script > through http and looking at the results for about 150 > reloads on two different days. > > This is the first time I'm sending a PHP report so I don't > know exactly what information to provide. Please ask for > more if as you see fit. > > ------------------------------------------------------------------------ > > Edit this bug report at > http://bugs.php.net/?id=12455&edit=1 > > -- > PHP Development Mailing List <http://www.php.net/> > To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net > For additional commands, e-mail: php-dev-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.dev (#61477) next »