Class: ReadableRandom

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

Constant Summary collapse

VERSION =
File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
NON_READABLE =
%w[o O 0 1 l / = +]

Class Method Summary collapse

Class Method Details

.base64(size) ⇒ Object



23
24
25
# File 'lib/readable_random.rb', line 23

def self.base64(size)
  random_string(size)[0...size]
end

.get(size) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/readable_random.rb', line 8

def self.get(size)
  try = random_string(size * 2)
  try = try.split('').reject{|x| NON_READABLE.include? x}.join('')

  if try.length < size #too many excluded characters !?
    get(size) #try once again...
  else
    try[0...size]
  end
end

.hex(size) ⇒ Object



19
20
21
# File 'lib/readable_random.rb', line 19

def self.hex(size)
  random_string(size).unpack("H*")[0][0...size]
end