note 91287 deleted from function.rand by danbrown

From: Date: Thu, 04 Jun 2009 00:51:57 +0000
Subject: note 91287 deleted from function.rand by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-156341@lists.php.net to get a copy of this message
Note Submitter: grayda dot NOSPAM at DONTSPAM dot solidinc dot org ---- Here's an even better random string generator: <?php function generateRandomString($length, $upper = false) { # 33, 126 all characters # 65, 90 uppercase # 97, 122 lowercase $str = ""; # Nothing yet for($i = 0; $i <= $length; $i++) { if($upper) { # If we want only uppercase $str .= chr(rand(65,90)); } else { $str .= chr(rand(97, 122)); } } } ?> Of course this is really simple, but it's far better than the dozens of lines of code currently used to create random strings

« previous php.notes (#156341) next »