15
strrand
strrand
SYNOPSIS
strrand($charset, $len)
DESCRIPTION
strrand returns a string of $len random characters selected from the character set $charset.
EXAMPLE
php > require 'library/strrand.php';
php > var_dump(strrand('ABC123', 8));
string(8) "A31C12BA"
CODE
- function strrand($charset, $len) {
- $max=strlen($charset)-1;
- $s = '';
- for ($i=0; $i < $len; $i++) {
- $s .= $charset[rand(0, $max)];
- }
- return $s;
- }
Comments