sub randomPasswordFromAlphabet($$) { my($alphabetRef, $passwordLen) = @_; my($alphabetLen) = scalar(@$alphabetRef); my($password, $r, $c); for (1..$passwordLen) { $r = rand($alphabetLen); $c = $$alphabetRef[$r]; $password .= $c; } return $password; } sub exampleUse() { my(@alphabet) = ('a'..'z','A'..'Z','0'..'9'); my($password) = randomPasswordFromAlphabet(\@alphabet, 8); print "$password\n"; }
Programming Tips - Perl: random password from an alphabet (list of characters)
Date: 2020apr4
Language: perl
Keywords: with no library
Q. Perl: random password from an alphabet (list of characters)
A.