Class: Statistical::Rng::Uniform

Inherits:
Object
  • Object
show all
Defined in:
lib/statistical/rng/uniform.rb

Overview

Companion RNG class for the continuous uniform distribution. Requires a

distrbution object of the corresponding distribution

Author:

  • Vaibhav Yenamandra

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dobj = nil, seed = Random.new_seed) ⇒ Uniform

Returns a new instance of Uniform.



15
16
17
18
19
20
21
22
23
24
25
# 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

Instance Attribute Details

#generatorObject (readonly)

Returns the value of attribute generator.



13
14
15
# File 'lib/statistical/rng/uniform.rb', line 13

def generator
  @generator
end

#lowerNumeric (readonly)

The lower bound of the uniform distribution.

Returns:

  • (Numeric)

    the current value of lower



12
13
14
# File 'lib/statistical/rng/uniform.rb', line 12

def lower
  @lower
end

#upperNumeric (readonly)

The upper bound of the uniform distribution.

Returns:

  • (Numeric)

    the current value of upper



12
13
14
# File 'lib/statistical/rng/uniform.rb', line 12

def upper
  @upper
end

Instance Method Details

#randObject

Return the next random number from the sequence

Returns:

  • next random number in the sequence

Author:

  • Vaibhav Yenamandra



32
33
34
# File 'lib/statistical/rng/uniform.rb', line 32

def rand
  @lower + @generator.rand * (@upper - @lower)
end

#typeStatistical::Distribution::Uniform

Return the type of the source distribution

Returns:

Author:

  • Vaibhav Yenamandra



54
55
56
# File 'lib/statistical/rng/uniform.rb', line 54

def type
  @sdist.class
end