Class: Kbbrandom::MakeA

Inherits:
Object
  • Object
show all
Defined in:
lib/kbbrandom.rb

Class Method Summary collapse

Class Method Details

.random_string(length, include_uppercase = true, include_lowercase = true, include_numbers = false) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/kbbrandom.rb', line 5

def self.random_string(length, include_uppercase = true, include_lowercase = true, include_numbers = false)
  o = []
  o.push ('a'..'z') if include_uppercase
  o.push ('A'..'Z') if include_lowercase
  
  o.push (0..9) if include_numbers
  o = o.map { |i| i.to_a }.flatten
  string = (0...length).map { o[rand(o.length)] }.join
end