Class | Random |
In: |
lib/random.rb
|
Parent: | Grammar |
Random is a class like no other. Random allows you do to fun things like ‘random.sentence’ and ‘random.position’. It takes no quarter. It asks for no parameters.
random = Random.new
For an overview on the Grammar system, please head over to the Grammar class. These are just mainly helper functions that interact with Grammar. For example,
random.sentence 'SENTENCE'
That would pull a random SENTENCE line out of your rules.txt, automatically replacing capitalized words with their rules.txt counterparts.
random.item 'NOUN'
That function pulls a random NOUN out. Some other randomness might randomly be added at a random point in time.
A skewed percentage between 20 and 75.
random.percentage
# File lib/random.rb, line 57 57: def percentage 58: 20+rand(55)+rand 59: end
A random ten digit phonenumber, yeehaw!
random.phone_number
# File lib/random.rb, line 75 75: def phone_number 76: number 10 77: end
Sleeps for a random amount of time between min and max
random.sleep 15,30
# File lib/random.rb, line 27 27: def sleep(min=30,max=45) 28: raise 'max cannot be less than min' if max < min 29: 30: seconds_to_sleep = (60*min + rand(60 * (max-min))) 31: puts "(#{Time.now.strftime("%H:%M")}) Sleeping for #{seconds_to_sleep/60} mins" 32: Kernel.sleep seconds_to_sleep 33: end