note 76658 added to function.mt-rand
| From: | www dot mrnaz dot com at osu1 dot php dot net | Date: | Wed, 25 Jul 2007 05:00:26 +0000 |
| Subject: | note 76658 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128900@lists.php.net to get a copy of this message | ||
This function uses mt_rand() to create a random string of specified length from an optionally
supplied string of characters. It is good for generating passwords that only consist of alphanumeric
characters or codes that must consist of a defined character space such as for barcodes. It can also
be used to generate random hexadecimal numbers for things like encryption keys.
It is very fast, and allows for generation of strings of unlimited length.
<?php
function rand_string($len, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')
{
$string = '';
for ($i = 0; $i < $len; $i++)
{
$pos = rand(0, strlen($chars)-1);
$string .= $chars{$pos};
}
return $string;
}
?>
----
Server IP: 203.202.10.60
Probable Submitter: 203.214.95.166
----
Manual Page -- http://www.php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/76658
Del: integrated -- https://master.php.net/note/delete/76658/integrated
Del: useless -- https://master.php.net/note/delete/76658/useless
Del: bad code -- https://master.php.net/note/delete/76658/bad+code
Del: spam -- https://master.php.net/note/delete/76658/spam
Del: non-english -- https://master.php.net/note/delete/76658/non-english
Del: in docs -- https://master.php.net/note/delete/76658/in+docs
Del: other reasons-- https://master.php.net/note/delete/76658
Reject -- https://master.php.net/note/reject/76658
Search -- https://master.php.net/manage/user-notes.php