Class: TimeTurner
- Inherits:
-
Object
- Object
- TimeTurner
- Defined in:
- lib/version.rb,
lib/time_turner.rb
Constant Summary collapse
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#big_bang ⇒ Time
readonly
Returns random time that will act as the epoch for the class instance.
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#initialize(seed) ⇒ TimeTurner
constructor
Initialize TimeTurner pseudo-random generator with a seed value.
-
#rand(range = 0.0..1) ⇒ Time
Generates random value within the range provided By default, returns a floating point number between 0 and 1.
Constructor Details
#initialize(seed) ⇒ TimeTurner
Initialize TimeTurner pseudo-random generator with a seed value
14 15 16 17 18 19 |
# File 'lib/time_turner.rb', line 14 def initialize(seed) @seed = seed @generator = Random.new(seed) @big_bang = Time.at(@generator.rand(0..Time.utc(2420).to_i)) @log = [] end |
Instance Attribute Details
#big_bang ⇒ Time (readonly)
Returns random time that will act as the epoch for the class instance
8 9 10 |
# File 'lib/time_turner.rb', line 8 def big_bang @big_bang end |
#log ⇒ Object (readonly)
Returns the value of attribute log.
9 10 11 |
# File 'lib/time_turner.rb', line 9 def log @log end |
Instance Method Details
#rand(range = 0.0..1) ⇒ Time
Generates random value within the range provided By default, returns a floating point number between 0 and 1
27 28 29 30 31 |
# File 'lib/time_turner.rb', line 27 def rand(range = 0.0..1) time = @generator.rand(range) @log << { constraint: range, val: time } time end |