Skip to content

Instantly share code, notes, and snippets.

@emerose
Created May 14, 2010 19:34
Show Gist options
  • Select an option

  • Save emerose/401558 to your computer and use it in GitHub Desktop.

Select an option

Save emerose/401558 to your computer and use it in GitHub Desktop.
def random_password(length=10)
allowed_chars = (('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a)
ret = ''
OpenSSL::Random.random_bytes(length).each_byte do |b|
ret << allowed_chars[b % allowed_chars.length]
end
return ret
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment