Class: RandomSet::Gaussian
- Inherits:
-
Object
- Object
- RandomSet::Gaussian
- Defined in:
- lib/random_set/gaussian.rb
Overview
Generates a Gaussian (normally distributed) random number, using the given mean and standard deviation.
Instance Method Summary collapse
-
#initialize(mean, stddev, rand_helper = lambda { Kernel.rand }) ⇒ Gaussian
constructor
Initializes the generator.
- #next ⇒ Object
Constructor Details
#initialize(mean, stddev, rand_helper = lambda { Kernel.rand }) ⇒ Gaussian
Initializes the generator.
15 16 17 18 19 20 21 |
# File 'lib/random_set/gaussian.rb', line 15 def initialize(mean, stddev, rand_helper = lambda { Kernel.rand }) @rand_helper = rand_helper @mean = mean @stddev = stddev @valid = false @next = 0 end |
Instance Method Details
#next ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/random_set/gaussian.rb', line 23 def next if @valid then @valid = false return @next else @valid = true x, y = self.class.gaussian(@mean, @stddev, @rand_helper) @next = y return x end end |