note 17426 added to function.mt-rand

From: Date: Sat, 08 Dec 2001 06:45:47 +0000
Subject: note 17426 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-22061@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 -- http://www.php.net/manual/en/function.mt-rand.php http://master.php.net/manage/user-notes.php?action=edit+17426 http://master.php.net/manage/user-notes.php?action=delete+17426 http://master.php.net/manage/user-notes.php?action=reject+17426

« previous php.notes (#22061) next »