Class: NormalRandom

Inherits:
Object
  • Object
show all
Defined in:
lib/normal_random.rb,
lib/normal_random/version.rb

Constant Summary collapse

DEFAULT_MU =
100
DEFAULT_SIGMA =
15
VERSION =
'1.0.0'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNormalRandom

Returns a new instance of NormalRandom.



10
11
12
# File 'lib/normal_random.rb', line 10

def initialize
  self.rng = Random.new
end

Instance Attribute Details

#rngObject

Returns the value of attribute rng.



8
9
10
# File 'lib/normal_random.rb', line 8

def rng
  @rng
end

Instance Method Details

#box_mullerObject Also known as: standard_deviations



18
19
20
# File 'lib/normal_random.rb', line 18

def box_muller
  Math.sqrt(-2*Math.log(rng.rand))*Math.cos(2*Math::PI*rng.rand)
end

#rand(mu: DEFAULT_MU, sigma: DEFAULT_SIGMA) ⇒ Object



14
15
16
# File 'lib/normal_random.rb', line 14

def rand(mu: DEFAULT_MU, sigma: DEFAULT_SIGMA)
  (standard_deviations * sigma) + mu
end