10
strrand
strrand
SYNOPSIS
strrand($charset, $len)
DESCRIPTION
strrand retourne une chaîne de caractères de longueur $len composée de caractères choisis aléatoirement dans le jeu de caractères $charset.
EXEMPLE
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;
- }
Commentaires