Skip to content

Instantly share code, notes, and snippets.

@femoco
Created March 28, 2009 18:17
Show Gist options
  • Save femoco/87164 to your computer and use it in GitHub Desktop.
Save femoco/87164 to your computer and use it in GitHub Desktop.
def get_random_string(length=5)
source=("a".."z").to_a + ("A".."Z").to_a + (0..9).to_a + ["_","-","."]
key=""
length.times{ key += source[rand(source.size)].to_s }
return key
end
@tsboh
Copy link

tsboh commented Jun 21, 2018

Thank you! Usefull

@GGrassiant
Copy link

Thanks a lot!

Copy link

ghost commented Jan 17, 2020

Thank u!!!!

@hassanss1
Copy link

´Hey Femoco,

Thank you! This was really useful. Though, when I tried to use it to generate a string with repetitive letters it won't work. It seems it does not generate a string with repetitive letters, do you imagine why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment