Skip to content

Instantly share code, notes, and snippets.

@pjc0247
Created March 5, 2013 13:02
Show Gist options
  • Save pjc0247/5090169 to your computer and use it in GitHub Desktop.
Save pjc0247/5090169 to your computer and use it in GitHub Desktop.
generate a random created string
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