Class: RubyOnAcid::RandomWalkFactory
- Defined in:
- lib/rubyonacid/factories/random_walk.rb
Overview
Increments from the minimum value, stopping at the maximum, or decrements from the maximum value, stopping at the minimum.
Instance Attribute Summary collapse
-
#interval ⇒ Object
The maximum amount to change counters by.
Instance Method Summary collapse
-
#get_unit(key) ⇒ Object
Increment counter for given key and return it.
-
#initialize(interval = 0.001) ⇒ RandomWalkFactory
constructor
A new instance of RandomWalkFactory.
Methods inherited from Factory
#boolean, #choose, #get, #within
Constructor Details
#initialize(interval = 0.001) ⇒ RandomWalkFactory
Returns a new instance of RandomWalkFactory.
11 12 13 14 15 16 |
# File 'lib/rubyonacid/factories/random_walk.rb', line 11 def initialize(interval = 0.001) super @start_value = 0.0 @values = {} @interval = interval end |
Instance Attribute Details
#interval ⇒ Object
The maximum amount to change counters by.
9 10 11 |
# File 'lib/rubyonacid/factories/random_walk.rb', line 9 def interval @interval end |
Instance Method Details
#get_unit(key) ⇒ Object
Increment counter for given key and return it. Constrain between 0 and 1.
19 20 21 22 23 24 25 |
# File 'lib/rubyonacid/factories/random_walk.rb', line 19 def get_unit(key) @values[key] ||= rand @values[key] += (rand * (2 * @interval)) - @interval @values[key] = 1.0 if @values[key] > 1.0 @values[key] = 0.0 if @values[key] < 0.0 @values[key] end |