Skip to content

Instantly share code, notes, and snippets.

@alexisbernard
Created January 6, 2010 22:14
Show Gist options
  • Save alexisbernard/270730 to your computer and use it in GitHub Desktop.
Save alexisbernard/270730 to your computer and use it in GitHub Desktop.
Generate random string
# Generates a random String
# 'abc'.rand(10) # => 'aacbacccbc'
class String
def rand(length)
(1..length).inject('') {|str, i| str << self[Kernel::rand(self.length)]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment