note 53170 deleted from function.rand by felipe

From: Date: Sun, 09 Dec 2007 15:36:43 +0000
Subject: note 53170 deleted from function.rand by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-133057@lists.php.net to get a copy of this message
Note Submitter: snecx at yahoo dot com ---- The following would be a much cleaner code to produce a nice random password. The substr function is removed. <?php $length = 16; $key_chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; $rand_max = strlen($keychars) - 1; for ($i = 0; $i < $length; $i++) { $rand_pos = rand(0, $max); $rand_key[] = $key_chars{$rand_pos}; } $rand_pass = implode('', $rand_key); echo $rand_pass; ?>

« previous php.notes (#133057) next »