note 43716 added to function.rand

From: Date: Thu, 01 Jul 2004 05:43:04 +0000
Subject: note 43716 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-72225@lists.php.net to get a copy of this message
I made a random password generator function that does not use strings, but with pretend strings (that are much faster): <?php function rand_pass() { // Get the alphabet for ($i = 97; $i <= 122; $i++) { $str[$i] = chr($i); } // Here we set $rand_str to $str[] with a random string $rand_str = $str[rand(97, 122)]; $rand_str .= $str[rand(97, 122)]; $rand_str .= $str[rand(97, 122)]; // Get the numerals for ($i = 48; $i <= 57; $i++) { $num[$i] = chr($i); } // Do the same as the strings here $rand_num = $num[rand(48, 57)]; $rand_num .= $num[rand(48, 57)]; $rand_num .= $num[rand(48, 57)]; $rand_num .= $num[rand(48, 57)]; // Put it together with a nice, easier to remember format $password = $rand_str . $rand_num; return $password; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43716 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43716&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43716&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#72225) next »