Class: Random

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

Overview

Magician's extensions to the Random class.

Instance Method Summary collapse

Instance Method Details

#booleanBoolean

Returns a random boolean (true or false).


13
14
15
# File 'lib/magician/random.rb', line 13

def boolean
  [true, false].sample random: self
end

#coinString

Returns a random coin toss (heads or tails).


20
21
22
# File 'lib/magician/random.rb', line 20

def coin
  ['heads', 'tails'].sample random: self
end

#dieFixnum

Returns a random die roll (from 1-6).


27
28
29
# File 'lib/magician/random.rb', line 27

def die
  rand 1..6
end