class Nifty::Utils::RandomString

Constants

LETTERS
NUMBERS
SYMBOLS
WORD_CHARS

Public Class Methods

generate(options = {}) click to toggle source
# File lib/nifty/utils/random_string.rb, line 10
def self.generate(options = {})
  options[:length]  ||= 30
  options[:symbols] ||= false
  chars = WORD_CHARS
  chars += SYMBOLS if options[:symbols]
  (
    [LETTERS[rand(LETTERS.size)]] +
    (0...options[:length]-2).map{ chars[rand(chars.size)] } +
    [LETTERS[rand(LETTERS.size)]]
  ).join
end