Skip to content

Instantly share code, notes, and snippets.

@wulftone
Created October 5, 2011 23:59
Show Gist options
  • Save wulftone/1266105 to your computer and use it in GitHub Desktop.
Save wulftone/1266105 to your computer and use it in GitHub Desktop.
Generate a random string (extracted from WEBrick)
# extracted from the WEBrick::Utils module
RAND_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz"
def random_string(len)
rand_max = RAND_CHARS.bytesize
ret = ""
len.times{ ret << RAND_CHARS[rand(rand_max)] }
ret
end
# random_string 10
#=> "Cty07iLWY9"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment