Created
August 15, 2014 03:47
-
-
Save pobing/f8d5662e0746bcc4c7da to your computer and use it in GitHub Desktop.
Generate random str(slug) with ruby
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 slug(length=10) | |
chars = ('A'..'Z').to_a + ('a'..'z').to_a + (0..9).to_a | |
chars.sample(length).join | |
end | |
#usage: | |
slug | |
=> "x5ZlWb4Ymf" | |
slug(6) | |
=> "bD3hVZ" | |
slug(8) | |
=> "6kDnqvdB" | |
learn by : http://stackoverflow.com/questions/88311/how-best-to-generate-a-random-string-in-ruby |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment