Skip to content

Instantly share code, notes, and snippets.

@jaysonrowe
Created November 1, 2011 01:58
Show Gist options
  • Select an option

  • Save jaysonrowe/1329634 to your computer and use it in GitHub Desktop.

Select an option

Save jaysonrowe/1329634 to your computer and use it in GitHub Desktop.
Random String Generator
SPCHAR = %w['~`!@#$%^&*()_-+={[}]|\:;"<,>.?/'].shuffle[0..2]
UPCHAR = ('A'..'Z').to_a.shuffle[0..4]
CHAR = ('a'..'z').to_a.shuffle[0..4]
NUMCHAR = ('0'..'9').to_a.shuffle[0..4]
def random_string(length=15)
s = SPCHAR
c = CHAR
u = UPCHAR
n = NUMCHAR
@password = s + c + n + u
@password.sort_by { rand }.join[0..length]
end
puts random_string.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment