note 76886 deleted from function.rand by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:46:35 +0000 |
| Subject: | note 76886 deleted from function.rand by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134458@lists.php.net to get a copy of this message | ||
Note Submitter: mno2go at gmail dot com
----
Perhaps not the most efficient way, but one that is quite simple and provides for easy control over
characters used in the generated strings/passwords:
<?php
function generateCode($length=6) {
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPRQSTUVWXYZ0123456789";
$code = "";
while (strlen($code) < $length) {
$code .= $chars[mt_rand(0,strlen($chars))];
}
return $code;
}
?>