Skip to content

Instantly share code, notes, and snippets.

@awesome
Created August 17, 2009 04:51
Show Gist options
  • Save awesome/168918 to your computer and use it in GitHub Desktop.
Save awesome/168918 to your computer and use it in GitHub Desktop.
# http://stackoverflow.com/questions/88311/how-best-to-generate-a-random-string-in-ruby
# Kent Fredric:
(0...8).map{65.+(rand(25)).chr}.join
# I spend too much time golfing.
(0...50).map{ ('a'..'z').to_a[rand(26)] }.join
# For lots of good WTFBBQ factor.
# And one more that's even more confusing, but more flexible and wastes less cycles:
o = [('a'..'z'),('A'..'Z')].map{|i| i.to_a}.flatten;
string = (0..50).map{ o[rand(o.length)] }.join;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment