module SafeRandom
Constants
- VERSION
Public Class Methods
alphanumeric(_length = 32, _case = nil)
click to toggle source
# File lib/safe_random/base.rb, line 10 def self.alphanumeric(_length = 32, _case = nil) random(_length, Constants::SET_ALPHANUMBERIC) end
generate_token(_length)
click to toggle source
# File lib/safe_random/base.rb, line 40 def self.generate_token(_length) Digest::SHA1.hexdigest([Time.now, rand].join)[0.._length] end
number(_length = 32)
click to toggle source
# File lib/safe_random/base.rb, line 2 def self.number(_length = 32) random(_length, Constants::SET_NUMBER) end
paragraphs(num = 2)
click to toggle source
# File lib/safe_random/text.rb, line 17 def self.paragraphs(num = 2) text = '' num.times do (rand(5) + 1).times do text += Constants::SET_PARAGRAPH.sample + '. ' end text += "\n\n" end text end
random(len = 32, character_set)
click to toggle source
sentences(num = 1)
click to toggle source
> Returns a given number of paragraphs delimited by two newlines (defaults to two paragraphs),¶ ↑
> using a small pool of generic sentences.¶ ↑
> SafeRandom.sentences
¶ ↑
> SafeRandom.paragraphs
¶ ↑
“I might jump an open drawbridge or Tarzan from a vine, beause I'm the unknown stuntman that makes Eastwood look so fine.nn Always fighting all the evil forces bringing peace and justice to all. nn”
# File lib/safe_random/text.rb, line 9 def self.sentences(num = 1) sentences = '' num.times do sentences += Constants::SET_PARAGRAPH.sample + '. ' end sentences.strip end
single(_type)
click to toggle source
# File lib/safe_random/base.rb, line 44 def self.single(_type) case _type when 'number' random(1, Constants::SET_NUMBER) when 'upcase' random(1, Constants::SET_UPCASE) when 'downcase' random(1, Constants::SET_DOWNCASE) when 'symbol' random(1, Constants::SET_SYMBOL) else random(1, Constants::SET_ALPHANUMBERIC) end end
small_token()
click to toggle source
# File lib/safe_random/base.rb, line 14 def self.small_token generate_token(6) end
string(_length = 32, _case = nil)
click to toggle source
# File lib/safe_random/base.rb, line 6 def self.string(_length = 32, _case = nil) random(_length, Constants::SET_STRING) end
strong_string(_len = 32)
click to toggle source
# File lib/safe_random/base.rb, line 29 def self.strong_string(_len = 32) _len = 8 if _len < 5 [single('number'), single('symbol'), single('upcase'), single('downcase'), alphanumeric(_len - 4)] .shuffle .join end
token()
click to toggle source
# File lib/safe_random/base.rb, line 18 def self.token generate_token(10) end