Skip to content

Instantly share code, notes, and snippets.

@nisanthchunduru
Created September 19, 2015 10:43
Show Gist options
  • Save nisanthchunduru/4a472ed8614ec714270d to your computer and use it in GitHub Desktop.
Save nisanthchunduru/4a472ed8614ec714270d to your computer and use it in GitHub Desktop.
Generate a random string in ruby
class RandomStringGenerator
CHARACTERS = ('a'..'z').to_a
def self.generate(length)
new.generate(length)
end
def generate(length)
length.times.map { random_character }.join
end
def random_character
CHARACTERS[rand(CHARACTERS.length)]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment