Skip to content

Instantly share code, notes, and snippets.

@msadouni
Created January 22, 2010 10:09
Show Gist options
  • Save msadouni/283664 to your computer and use it in GitHub Desktop.
Save msadouni/283664 to your computer and use it in GitHub Desktop.
Generates a random string via the commande line
#!/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