Class: Spark::RandomGenerator::Poisson
- Inherits:
-
Object
- Object
- Spark::RandomGenerator::Poisson
- Defined in:
- lib/spark/sampler.rb
Instance Method Summary collapse
-
#initialize(mean, seed) ⇒ Poisson
constructor
A new instance of Poisson.
- #rand ⇒ Object
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
#rand ⇒ Object
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 |