module RandomData::Text

Public Instance Methods

alphanumeric(size=16) click to toggle source

Returns a string of random upper- and lowercase alphanumeric characters. Accepts a size parameters, defaults to 16 characters.

>> Random.alphanumeric

“Ke2jdknPYAI8uCXj”

>> Random.alphanumeric(5)

“7sj7i”

# File lib/random_data/text.rb, line 17
def alphanumeric(size=16)
  s = ""
  size.times { s << (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }
  s
end
paragraphs(num = 2) 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. >> Random.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/random_data/text.rb, line 55
def paragraphs(num = 2)
  text = ''
 
  num.times do 
    (rand(5)+1).times do
      text += @@sentences.rand + '. '
    end
    text += "\n\n"
  end
 
  return text
 
end