class Statistical::Rng::Uniform

Companion RNG class for the continuous uniform distribution. Requires a

distrbution object of the corresponding distribution

@author Vaibhav Yenamandra

@attr_reader [Numeric] lower The lower bound of the uniform distribution. @attr_reader [Numeric] upper The upper bound of the uniform distribution.

Attributes

generator[R]
lower[R]
upper[R]

Public Class Methods

new(dobj = nil, seed = Random.new_seed) click to toggle source
# File lib/statistical/rng/uniform.rb, line 15
def initialize(dobj = nil, seed = Random.new_seed)
  unless dobj.nil? || dobj.is_a?(Statistical::Distribution::Uniform)
    raise TypeError,
          "Expected Distribution object or nil, found #{dobj.class}"
  end
  dobj = Statistical::Distribution::Uniform.new if dobj.nil?
  @generator = Random.new(seed)
  @lower = dobj.lower
  @upper = dobj.upper
  @sdist = dobj
end

Public Instance Methods

==(other)
Alias for: eql?
rand() click to toggle source

Return the next random number from the sequence

@author Vaibhav Yenamandra

@return next random number in the sequence

# File lib/statistical/rng/uniform.rb, line 32
def rand
  @lower + @generator.rand * (@upper - @lower)
end
type() click to toggle source

Return the type of the source distribution

@author Vaibhav Yenamandra

@return [Statistical::Distribution::Uniform] source distribution's type

# File lib/statistical/rng/uniform.rb, line 54
def type
  @sdist.class
end

Private Instance Methods

eql?(other) click to toggle source

Compare against another rng to see if they are the same

@author Vaibhav Yenamandra

@return [Boolean] true if and only if, source distributions are the

same and the prng has the same initial state
# File lib/statistical/rng/uniform.rb, line 42
def eql?(other)
  return other.is_a?(self.class) &&
         @lower == other.lower &&
         @upper == other.upper &&
         @generator == other.generator
end
Also aliased as: ==