Class: NormalRandom
- Inherits:
-
Object
- Object
- NormalRandom
- 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
-
#rng ⇒ Object
Returns the value of attribute rng.
Instance Method Summary collapse
- #box_muller ⇒ Object (also: #standard_deviations)
-
#initialize ⇒ NormalRandom
constructor
A new instance of NormalRandom.
- #rand(mu: DEFAULT_MU, sigma: DEFAULT_SIGMA) ⇒ Object
Constructor Details
#initialize ⇒ NormalRandom
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
#rng ⇒ Object
Returns the value of attribute rng.
8 9 10 |
# File 'lib/normal_random.rb', line 8 def rng @rng end |
Instance Method Details
#box_muller ⇒ Object 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 |