class RV::Geometric

Geometric generator. Number of trials until first “success”.

Arguments
  • p -> the probability of success (0 < p < 1; default: 0.5).

  • rng -> the (Enumerable) source of U(0, 1)'s (default: U_GENERATOR)

Attributes

p[R]

Public Class Methods

new(p: 0.5, rng: U_GENERATOR) click to toggle source
# File lib/random_variates.rb, line 439
def initialize(p: 0.5, rng: U_GENERATOR)
  raise 'Require 0 < p < 1.' if p <= 0 || p >= 1

  @p = p
  @log_q = Math.log(1 - p)
  @rng = rng
end

Public Instance Methods

next() click to toggle source
# File lib/random_variates.rb, line 447
def next
  (Math.log(1.0 - @rng.next) / @log_q).ceil
end