class Digiproc::Strategies::GaussianGeneratorBoxMullerStrategy
Class for generating random numbers from a Gaussin Population of a given mean or standard deviation
Attributes
mean[RW]
stddev[RW]
Public Class Methods
new(mean = 0, stddev = 1)
click to toggle source
rand2()
click to toggle source
No input args Returns 2 random numbers from a gaussain population with stddev of 1 and mean of 0
# File lib/strategies/gaussian/gaussian_generator.rb, line 10 def self.rand2 uniform_random = Random.new r = (-2 * Math.log(1 - uniform_random.rand)) ** 0.5 theta = 2 * Math::PI * (1 - uniform_random.rand) return r * Math.cos(theta), r * Math.sin(theta) end
Public Instance Methods
rand()
click to toggle source
Get a single random number from a Gaussian distribution with a mean and stddev as defined by @mean and @stddev Use the .rand2 method to get 2 random numbers. Save one, return the other
# File lib/strategies/gaussian/gaussian_generator.rb, line 32 def rand if @needs_gen x,y = self.class.rand2 @next = y @needs_gen = false return self.mean + self.stddev * x else @needs_gen = true return self.mean + self.stddev * @next end end
rand2()
click to toggle source
Calls the .rand2 method
# File lib/strategies/gaussian/gaussian_generator.rb, line 45 def rand2 self.class.rand2 end