class RV::Uniform

Generate values uniformly distributed between min and max.

Arguments
  • min -> the lower bound for the range (default: 0).

  • max -> the upper bound for the range (default: 1).

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

Attributes

max[R]
min[R]
range[R]

Public Class Methods

new(min: 0.0, max: 1.0, rng: U_GENERATOR) click to toggle source
# File lib/random_variates.rb, line 45
def initialize(min: 0.0, max: 1.0, rng: U_GENERATOR)
  raise 'Max must be greater than min.' if max <= min
  @min = min
  @max = max
  @range = max - min
  @rng = rng
end

Public Instance Methods

next() click to toggle source
# File lib/random_variates.rb, line 53
def next
  @min + @range * @rng.next
end