note 17426 deleted from function.mt-rand by jimw

From: Date: Thu, 20 Dec 2001 22:21:14 +0000
Subject: note 17426 deleted from function.mt-rand by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-23484@lists.php.net to get a copy of this message
This bit of code will return a random string of a given length containing the characters 0-9, a-z, and A-Z. function string_rand($randlen) { mt_srand((double)microtime() * 100000); for($i=0; $i<$randlen; $i++) { switch(mt_rand(0, 2)) { case 0: $ranstr .= chr(mt_rand(0, 25) + 97); break; case 1: $ranstr .= chr(mt_rand(0, 25) + 65); break; case 2: $ranstr .= mt_rand(0, 9); break; } } return $ranstr; } I have needed to use this many times, and thought that you too might find it useful. -Aaron

« previous php.notes (#23484) next »