Class: Statistical::Rng::Uniform
- Inherits:
-
Object
- Object
- Statistical::Rng::Uniform
- Defined in:
- lib/statistical/rng/uniform.rb
Overview
Companion RNG class for the continuous uniform distribution. Requires a
distrbution object of the corresponding distribution
Instance Attribute Summary collapse
-
#generator ⇒ Object
readonly
Returns the value of attribute generator.
-
#lower ⇒ Numeric
readonly
The lower bound of the uniform distribution.
-
#upper ⇒ Numeric
readonly
The upper bound of the uniform distribution.
Instance Method Summary collapse
-
#initialize(dobj = nil, seed = Random.new_seed) ⇒ Uniform
constructor
A new instance of Uniform.
-
#rand ⇒ Object
Return the next random number from the sequence.
-
#type ⇒ Statistical::Distribution::Uniform
Return the type of the source distribution.
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
#generator ⇒ Object (readonly)
Returns the value of attribute generator.
13 14 15 |
# File 'lib/statistical/rng/uniform.rb', line 13 def generator @generator end |
#lower ⇒ Numeric (readonly)
The lower bound of the uniform distribution.
12 13 14 |
# File 'lib/statistical/rng/uniform.rb', line 12 def lower @lower end |
#upper ⇒ Numeric (readonly)
The upper bound of the uniform distribution.
12 13 14 |
# File 'lib/statistical/rng/uniform.rb', line 12 def upper @upper end |
Instance Method Details
#rand ⇒ Object
Return the next random number from the sequence
32 33 34 |
# File 'lib/statistical/rng/uniform.rb', line 32 def rand @lower + @generator.rand * (@upper - @lower) end |
#type ⇒ Statistical::Distribution::Uniform
Return the type of the source distribution
54 55 56 |
# File 'lib/statistical/rng/uniform.rb', line 54 def type @sdist.class end |