Created
August 11, 2009 18:37
-
-
Save dcparker/166041 to your computer and use it in GitHub Desktop.
String.random
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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