in reply to Re: String randomness
in thread String randomness
I can't resist golfing this a bit.. but the following is not necessarily for use in production. :-)my @pass_char = ('a'..'z', 'A'..'Z', 0 .. 9, qw(_ . @)); sub generate_password { my $len = shift || 12; my $pass; $pass .= $pass_char[rand @pass_char] for 1 .. $len; return $pass; }
____________my @pass_char = ('a'..'z', 'A'..'Z', 0 .. 9, qw(_ . @)); sub generate_password { return join '', map $pass_char[rand @pass_char], 1 .. (shift || 12 +); }
|
|---|