Class: RubyPager::GaussianNoise

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_pager/gaussian_noise.rb

Instance Method Summary collapse

Constructor Details

#initialize(ex_mean, ex_stddev, ex_rand_helper = lambda { Kernel.rand }) ⇒ GaussianNoise

Returns a new instance of GaussianNoise.



5
6
7
8
9
10
11
# File 'lib/ruby_pager/gaussian_noise.rb', line 5

def initialize(ex_mean, ex_stddev, ex_rand_helper = lambda { Kernel.rand })
  @rand_helper = ex_rand_helper
  @mean = ex_mean
  @stddev = ex_stddev
  @valid = false
  @next = 0
end

Instance Method Details

#randObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ruby_pager/gaussian_noise.rb', line 13

def rand
  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