class RV::Poisson
Poisson
generator.
- Arguments
-
rate
-> expected number per unit time/distance (rate
> 0; default: 1). -
rng
-> the (Enumerable
) source of U(0, 1)'s (default: U_GENERATOR)
-
Attributes
rate[R]
Public Class Methods
new(rate: 1.0, rng: U_GENERATOR)
click to toggle source
# File lib/random_variates.rb, line 405 def initialize(rate: 1.0, rng: U_GENERATOR) raise 'rate must be positive.' if rate <= 0 @rate = rate @threshold = Math.exp(-rate) @rng = rng end
Public Instance Methods
next()
click to toggle source
# File lib/random_variates.rb, line 420 def next count = 0 product = 1.0 count += 1 until (product *= @rng.next) < @threshold count end
rate=(rate)
click to toggle source
# File lib/random_variates.rb, line 413 def rate=(rate) raise 'Rate must be a number.' unless rate.is_a? Numeric raise 'Rate must be positive.' if rate <= 0 @rate = rate @threshold = Math.exp(-rate) end