Class: RandomDistribution::GaussianSequence
- Defined in:
- lib/redshift/util/random.rb
Constant Summary
Constants included from Math
Instance Attribute Summary collapse
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#mean ⇒ Object
readonly
Returns the value of attribute mean.
-
#min ⇒ Object
readonly
Returns the value of attribute min.
-
#stdev ⇒ Object
readonly
Returns the value of attribute stdev.
Attributes inherited from Sequence
Instance Method Summary collapse
-
#initialize(opt = {}) ⇒ GaussianSequence
constructor
A new instance of GaussianSequence.
- #next ⇒ Object
Methods inherited from Sequence
random_pool_seed, random_seed, serial_count
Constructor Details
#initialize(opt = {}) ⇒ GaussianSequence
Returns a new instance of GaussianSequence.
123 124 125 126 127 128 129 130 |
# File 'lib/redshift/util/random.rb', line 123 def initialize opt = {} super @mean = Float(opt[:mean] || 0) @stdev = Float(opt[:stdev] || 1) @min = opt[:min]; @min = Float(@min) if @min @max = opt[:max]; @max = Float(@max) if @max @nextnext = nil end |
Instance Attribute Details
#max ⇒ Object (readonly)
Returns the value of attribute max.
121 122 123 |
# File 'lib/redshift/util/random.rb', line 121 def max @max end |
#mean ⇒ Object (readonly)
Returns the value of attribute mean.
121 122 123 |
# File 'lib/redshift/util/random.rb', line 121 def mean @mean end |
#min ⇒ Object (readonly)
Returns the value of attribute min.
121 122 123 |
# File 'lib/redshift/util/random.rb', line 121 def min @min end |
#stdev ⇒ Object (readonly)
Returns the value of attribute stdev.
121 122 123 |
# File 'lib/redshift/util/random.rb', line 121 def stdev @stdev end |
Instance Method Details
#next ⇒ Object
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/redshift/util/random.rb', line 132 def next if @nextnext result = @mean + @nextnext*@stdev @nextnext = nil else begin v1 = 2 * super - 1 v2 = 2 * super - 1 rsq = v1*v1 + v2*v2 end while rsq >= 1 || rsq == 0 fac = sqrt(-2*log(rsq) / rsq) @nextnext = v1*fac result = @mean + v2*fac*@stdev end if @min and result < @min result = @min elsif @max and result > @max result = @max end return result end |