Class: Statistical::Rng::UniformDiscrete
- Inherits:
-
Object
- Object
- Statistical::Rng::UniformDiscrete
- Defined in:
- lib/statistical/rng/uniform_discrete.rb
Overview
Companion RNG class for the continuous uniform distribution. Requires a
distrbution object of the corresponding distribution
Instance Attribute Summary collapse
-
#generator ⇒ Numeric
readonly
The prng created with ‘seed` for usage as a source of randomness to base the current RNG on.
-
#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, seed = Random.new_seed) ⇒ UniformDiscrete
constructor
Companion RNG class for the continuous uniform distribution.
-
#members ⇒ Object
A call to expose the underlying distribution’s support set.
-
#rand ⇒ Object
Return the next random number from the sequence using Ruby’s ‘rand`.
-
#type ⇒ Object
Return the type of the source distribution.
Constructor Details
#initialize(dobj, seed = Random.new_seed) ⇒ UniformDiscrete
Companion RNG class for the continuous uniform distribution. Requires a
distrbution object of the corresponding distribution
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/statistical/rng/uniform_discrete.rb', line 24 def initialize(dobj, seed = Random.new_seed) unless dobj.nil? || dobj.is_a?(Statistical::Distribution::UniformDiscrete) raise TypeError, "Expected Distribution object or nil, found #{dobj.class}" end @generator = Random.new(seed) @lower = dobj.lower @upper = dobj.upper @sdist = dobj end |
Instance Attribute Details
#generator ⇒ Numeric (readonly)
The prng created with ‘seed` for usage as a source of randomness to base the current RNG on
14 15 16 |
# File 'lib/statistical/rng/uniform_discrete.rb', line 14 def generator @generator end |
#lower ⇒ Numeric (readonly)
The lower bound of the uniform distribution
14 15 16 |
# File 'lib/statistical/rng/uniform_discrete.rb', line 14 def lower @lower end |
#upper ⇒ Numeric (readonly)
The upper bound of the uniform distribution
14 15 16 |
# File 'lib/statistical/rng/uniform_discrete.rb', line 14 def upper @upper end |
Instance Method Details
#members ⇒ Object
A call to expose the underlying distribution’s support set
70 71 72 |
# File 'lib/statistical/rng/uniform_discrete.rb', line 70 def members return @sdist.support end |
#rand ⇒ Object
Return the next random number from the sequence using Ruby’s ‘rand`
40 41 42 43 |
# File 'lib/statistical/rng/uniform_discrete.rb', line 40 def rand n = members.count return members[@generator.rand(n)] end |
#type ⇒ Object
Return the type of the source distribution
63 64 65 |
# File 'lib/statistical/rng/uniform_discrete.rb', line 63 def type @sdist.class end |