Created
June 29, 2009 16:15
-
-
Save citizen428/137675 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def get_random_char | |
(r = rand(36)) < 26 ? (?a+r).chr : (?0+r-26).chr | |
end | |
# building a string using the above method | |
def generate_string(len) | |
raise ArgumentError if len < 1 | |
(1..len).map { get_random_char }.join | |
end | |
generate_string(7) # => "tf3c38b" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment