note 39805 added to function.mt-rand
| From: | php-general at lists dot php dot net | Date: | Wed, 11 Feb 2004 10:27:45 +0000 |
| Subject: | note 39805 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65003@lists.php.net to get a copy of this message | ||
Here is a example of a very small, compact, quite random-random string generator. It will make a
string with uppercase & lowercase letters, with numbers. You simply need to set $len in the
for() structure, and then the string will be in $r. It has been designed for size, while it's
still quite fast. Mind the wrapping, it should be 1 line.
<?php
for($len=8,$r='';strlen($r)<$len;$r.=chr(!mt_rand(0,2)?
mt_rand(48,57):(!mt_rand(0,1)?mt_rand(65,90):mt_rand
(97,122))));
?>
Armond Carroll
----
Manual Page -- http://www.php.net/manual/en/function.mt-rand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39805
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39805&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39805&report=yes
Search -- http://master.php.net/manage/user-notes.php