Class: ERV::UniformDistribution
- Inherits:
-
Distribution
- Object
- Distribution
- ERV::UniformDistribution
- Defined in:
- lib/erv/uniform_distribution.rb
Instance Method Summary collapse
-
#initialize(opts) ⇒ UniformDistribution
constructor
A new instance of UniformDistribution.
Methods inherited from Distribution
Constructor Details
#initialize(opts) ⇒ UniformDistribution
Returns a new instance of UniformDistribution.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/erv/uniform_distribution.rb', line 13 def initialize(opts) super(opts) raise ArgumentError unless opts[:max_value] max = opts[:max_value].to_f min = opts[:min_value].try(:to_f) || 0.0 if RUBY_PLATFORM == 'java' # create distribution d = UniformRealDistribution.new(@rng, min, max, UniformRealDistribution::DEFAULT_INVERSE_ABSOLUTE_ACCURACY) # setup sampling function @func = Proc.new { d.sample } else # setup sampling function @func = Proc.new { @rng.flat(min, max) } end end |