Created
January 22, 2010 10:09
-
-
Save msadouni/283664 to your computer and use it in GitHub Desktop.
Generates a random string via the commande line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/opt/local/bin/ruby | |
def random_string(length=15) | |
chars = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789' | |
password = '' | |
length.times { password << chars[rand(chars.size)] } | |
password | |
end | |
if ARGV.first | |
puts random_string(ARGV.first.to_i) | |
else | |
puts random_string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment