Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If it's not too hard...

Status
Not open for further replies.

PhoenixDown

Programmer
Joined
Jul 2, 2001
Messages
279
Location
CA
Can someone create a simple random number generator using only numeric characters, 25 characters, and only runs when it's ran in a certain sub routine? Also to call the generated number with s scaler variable.

Thank you. :-)
- Go there!
 
Here it is a similar one.


$passwd = random_password();

print &quot;Your random password is <b>$passwd</b>.<p>\n&quot;;

sub random_password {

($length) = @_;
if ($length eq &quot;&quot; or $length < 3) {
$length = 6; # make it at least 6 chars long.
}
$vowels = &quot;aeiouyAEUY&quot;;
$consonants = &quot;bdghjmnpqrstvwxzBDGHJLMNPQRSTVWXZ12345678&quot;;
srand(time() ^ ($$ + ($$ << 15)) );
$alt = int(rand(2)) - 1;
$s = &quot;&quot;;
$newchar = &quot;&quot;;
foreach $i (0..$length-1) {
if ($alt == 1) {
$newchar =
substr($vowels,rand(length($vowels)),1);
} else {
$newchar = substr($consonants,
rand(length($consonants)),1);
}
$s .= $newchar;
$alt = !$alt;
}
return $s;
}


-Aaron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top