Class: TimeTurner

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

Constant Summary collapse

VERSION =
"0.1.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seed) ⇒ TimeTurner

Initialize TimeTurner pseudo-random generator with a seed value

Parameters:

  • seed (Integer)


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_bangTime (readonly)

Returns random time that will act as the epoch for the class instance

Returns:

  • (Time)


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

def big_bang
  @big_bang
end

#logObject (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

Parameters:

  • range (Range) (defaults to: 0.0..1)

Returns:

  • (Time)


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