Class: ERV::UniformDistribution
- Inherits:
-
Distribution
- Object
- Distribution
- ERV::UniformDistribution
- Defined in:
- lib/erv/uniform_distribution.rb
Constant Summary
Constants inherited from Distribution
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ UniformDistribution
constructor
A new instance of UniformDistribution.
- #sample ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ UniformDistribution
Returns a new instance of UniformDistribution.
7 8 9 10 11 12 13 14 |
# File 'lib/erv/uniform_distribution.rb', line 7 def initialize(opts={}) super(opts) max = opts[:max_value]&.to_f raise ArgumentError unless max @min = opts.fetch(:min_value, 0.0).to_f @range = max - @min end |
Instance Method Details
#sample ⇒ Object
16 17 18 19 20 21 |
# File 'lib/erv/uniform_distribution.rb', line 16 def sample # starting from a random variable X ~ U(0,1), which is provided by the # RNG, we can obtain a random variable Y ~ U(a,b) through location-scale # transformation: Y = a + (b-a) X. see [KROESE11], section 3.1.2.2. @min + @range * @rng.rand end |