Class: TestBench::Random::Iterator

Inherits:
Object
  • Object
show all
Defined in:
lib/test_bench/random/iterator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(random) ⇒ Iterator



13
14
15
# File 'lib/test_bench/random/iterator.rb', line 13

def initialize(random)
  @random = random
end

Instance Attribute Details

#iterationsObject



6
7
8
# File 'lib/test_bench/random/iterator.rb', line 6

def iterations
  @iterations ||= 0
end

#randomObject (readonly)

Returns the value of attribute random.



11
12
13
# File 'lib/test_bench/random/iterator.rb', line 11

def random
  @random
end

#seedObject

Returns the value of attribute seed.



4
5
6
# File 'lib/test_bench/random/iterator.rb', line 4

def seed
  @seed
end

Class Method Details

.build(seed) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/test_bench/random/iterator.rb', line 17

def self.build(seed)
  random = self.random(seed)

  instance = new(random)
  instance.seed = seed
  instance
end

.random(seed) ⇒ Object



25
26
27
28
29
# File 'lib/test_bench/random/iterator.rb', line 25

def self.random(seed)
  random_seed = seed.to_i(36)

  ::Random.new(random_seed)
end

Instance Method Details

#iterated?Boolean



47
48
49
# File 'lib/test_bench/random/iterator.rb', line 47

def iterated?
  iterations > 0
end

#nextObject



31
32
33
34
35
# File 'lib/test_bench/random/iterator.rb', line 31

def next
  self.iterations += 1

  random.bytes(8)
end

#seed?(seed) ⇒ Boolean



37
38
39
40
41
42
43
44
45
# File 'lib/test_bench/random/iterator.rb', line 37

def seed?(seed)
  control_random = ::Random.new(random.seed)
  compare_random = Iterator.random(seed)

  control_value = control_random.rand
  compare_value = compare_random.rand

  control_value == compare_value
end