100) {
print "Error: \"Length\" out of range (1-100)
\n";
return;
}
if (!$num && !$uc && !$lc && !$oc) {
print "Error: No character types specified
\n";
return;
}
$s="";
$i=0;
do {
switch(mt_rand(1,4)) {
// get number - ASCII characters (0:48 through 9:57)
case 1:
if ($num==1) {
$s .= chr(mt_rand(48,57));
$i++;
}
break;
// get uppercase letter - ASCII characters (a:65 through z:90)
case 2:
if ($uc==1) {
$s .= chr(mt_rand(65,90));
$i++;
}
break;
// get lowercase letter - ASCII characters (A:97 through Z:122)
case 3:
if ($lc==1) {
$s .= chr(mt_rand(97,122));
$i++;
}
break;
// get other characters - ASCII characters
// !"#$%&'()*+,-./ :;<=>?@ [\]^_` {|}~
// (33-47, 58-64, 91-96, 123-126)
case 4:
if ($oc==1) {
switch(mt_rand(1,4)) {
case 1:
$s .= "" . mt_rand(33,47) . ";";
$i++;
break;
case 2:
$s .= "" . mt_rand(58,64) . ";";
$i++;
break;
case 3:
$s .= "" . mt_rand(91,96) . ";";
$i++;
break;
case 4:
$s .= "" . mt_rand(123,126) . ";";
$i++;
break;
}
}
break;
}
} while ($i<$len);
print "Character String: $s
\n";
}
?>