Skip to content

Instantly share code, notes, and snippets.

@pobing
Created August 15, 2014 03:47
Show Gist options
  • Save pobing/f8d5662e0746bcc4c7da to your computer and use it in GitHub Desktop.
Save pobing/f8d5662e0746bcc4c7da to your computer and use it in GitHub Desktop.
Generate random str(slug) with ruby
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