note 83100 deleted from function.array-rand by danbrown

From: Date: Tue, 27 Jan 2009 02:21:48 +0000
Subject: note 83100 deleted from function.array-rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-149819@lists.php.net to get a copy of this message
Note Submitter: knoffz at gmail dot com ---- "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." Do not trust in this! I tried to fill a database with 100.000 unique id's (in a loop). Each id 7 chars long with a numeric-loweralpha charset. When it came to around ~17.500 queries, the array_rand() function was unable to generate a new unique id from the charset. I don't think it's a bug. However, make sure to seed the random number generator by yourself. Either by adding _ srand((float) microtime() * 10000000); _ before the array_rand() function, or by shuffling the array first. PHP version was 5.2.5 by the way...

« previous php.notes (#149819) next »