Skip to content

Instantly share code, notes, and snippets.

@dcparker
Created August 11, 2009 18:37
Show Gist options
  • Save dcparker/166041 to your computer and use it in GitHub Desktop.
Save dcparker/166041 to your computer and use it in GitHub Desktop.
String.random
String::ALPHANUMERIC_CHARACTERS = ('a'..'z').to_a + ('A'..'Z').to_a
def String.random(size)
length = String::ALPHANUMERIC_CHARACTERS.length
(0...size).collect { String::ALPHANUMERIC_CHARACTERS[Kernel.rand(length)] }.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment