Created
March 5, 2013 13:02
-
-
Save pjc0247/5090169 to your computer and use it in GitHub Desktop.
generate a random created string
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
def generate_random_string(length = 8) | |
buffer = String.new | |
for i in 0..length | |
rnd = rand(26 + 26 + 10) | |
case rnd | |
when 0..25 | |
buffer << (rand(26) + 'a'.ord).chr | |
when 26..52 | |
buffer << (rand(26) + 'A'.ord).chr | |
else | |
buffer << (rand(10) + '0'.ord).chr | |
end | |
end | |
return buffer | |
end | |
begin | |
generated_string = generate_random_string | |
puts generated_string | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment