Class: Spark::RandomGenerator::Poisson

Inherits:
Object
  • Object
show all
Defined in:
lib/spark/sampler.rb

Instance Method Summary collapse

Constructor Details

#initialize(mean, seed) ⇒ Poisson

Returns a new instance of Poisson.



8
9
10
11
# File 'lib/spark/sampler.rb', line 8

def initialize(mean, seed)
  generator = Random.new(seed)
  @exp_rng = Distribution::Exponential.rng(1.0/mean, random: generator)
end

Instance Method Details

#randObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/spark/sampler.rb', line 13

def rand
  t = 0.0
  number = 0

  loop{
    t += @exp_rng.call
    if t > 1
      return number
    end
    number += 1
  }
end