Skip to content

Instantly share code, notes, and snippets.

@Narnach
Created January 8, 2009 12:15
Show Gist options
  • Select an option

  • Save Narnach/44704 to your computer and use it in GitHub Desktop.

Select an option

Save Narnach/44704 to your computer and use it in GitHub Desktop.
Generate a random alphanumeric password
#!/usr/bin/env ruby
# Random alphanumeric password generator
# Takes one parameter, which is the password length
# Forces the minimum length to be 10 or more
#
CHARS = (0..9).to_a + ('a'..'z').to_a + ('A'..'Z').to_a
class << CHARS
def rand
self[Kernel.rand(size)]
end
end
len = ARGV.first.to_i
len = 10 unless len > 0
len.times { print CHARS.rand}
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment