Module: Gemmy::Patches::StringPatch::InstanceMethods::Random

Defined in:
lib/gemmy/patches/string_patch.rb

Class Method Summary collapse

Class Method Details

.random(len = 32, character_set = ["A".."Z", "a".."z", "0".."9"]) ⇒ Object

facets a random string of length n with a given character set



292
293
294
295
296
# File 'lib/gemmy/patches/string_patch.rb', line 292

def self.random(len=32, character_set = ["A".."Z", "a".."z", "0".."9"])
  characters = character_set.map { |i| i.to_a }.flatten
  characters_len = characters.length
  (0...len).map{ characters[rand(characters_len)] }.join
end