Class: RV::Uniform
- Inherits:
-
Object
- Object
- RV::Uniform
- Includes:
- RV_Generator
- Defined in:
- lib/random_variates.rb
Overview
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)
-
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
-
#initialize(min: 0.0, max: 1.0, rng: U_GENERATOR) ⇒ Uniform
constructor
A new instance of Uniform.
- #next ⇒ Object
Methods included from RV_Generator
Constructor Details
#initialize(min: 0.0, max: 1.0, rng: U_GENERATOR) ⇒ Uniform
Returns a new instance of Uniform.
45 46 47 48 49 50 51 |
# 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 |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
43 44 45 |
# File 'lib/random_variates.rb', line 43 def max @max end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
43 44 45 |
# File 'lib/random_variates.rb', line 43 def min @min end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
43 44 45 |
# File 'lib/random_variates.rb', line 43 def range @range end |
Instance Method Details
#next ⇒ Object
53 54 55 |
# File 'lib/random_variates.rb', line 53 def next @min + @range * @rng.next end |