Module: Perpetual::String::Miscs

Defined in:
lib/perpetual/string/miscs.rb

Class Method Summary collapse

Class Method Details

.random(length = 10) ⇒ Object

Generates an alphanumeric pseudo-random string of length length (default: 10).



23
24
25
26
27
28
29
30
31
# File 'lib/perpetual/string/miscs.rb', line 23

def self.random(length = 10)
  dictionary        = (?a..?z).to_a + (?A..?Z).to_a + (?0..?9).to_a
  dictionary_length = dictionary.length
  ''.tap { |v|
    1.upto(length) {
      v << dictionary[rand(dictionary_length-1)]
    }
  }
end