Class: RandomVariable::Generic
- Inherits:
-
Object
- Object
- RandomVariable::Generic
- Defined in:
- lib/random_variable.rb
Instance Method Summary collapse
-
#initialize(&blk) ⇒ Generic
constructor
A new instance of Generic.
-
#outcome ⇒ Object
(also: #sample)
obtain a single outcome from the random variable.
-
#outcomes(number) ⇒ Object
(also: #samples)
obtain
numberoutcomes from the random variable.
Constructor Details
#initialize(&blk) ⇒ Generic
Returns a new instance of Generic.
51 52 53 |
# File 'lib/random_variable.rb', line 51 def initialize(&blk) @blk = blk end |
Instance Method Details
#outcome ⇒ Object Also known as: sample
obtain a single outcome from the random variable
72 73 74 |
# File 'lib/random_variable.rb', line 72 def outcome @blk.call end |
#outcomes(number) ⇒ Object Also known as: samples
obtain number outcomes from the random variable
78 79 80 81 82 83 84 |
# File 'lib/random_variable.rb', line 78 def outcomes(number) ary = [] number.times do ary << @blk.call end ary end |