Class: DbmsBuffers::SimpleGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/dbms_buffers/generators.rb

Overview

The SimpleGenerator generates random elements for putting into the buffer. By default, it generates a letter from A to Z. This can be adjusted using the range method, e.g. SimpleGenerator.new.range([‘A’, ‘B’, ‘C’])

Instance Method Summary collapse

Constructor Details

#initialize(seed = Random.new_seed) ⇒ SimpleGenerator

Returns a new instance of SimpleGenerator.



9
10
11
12
# File 'lib/dbms_buffers/generators.rb', line 9

def initialize(seed = Random.new_seed)
  @rng = Random.new(seed)
  @range = *('A'..'Z')
end

Instance Method Details

#getObject



19
20
21
22
# File 'lib/dbms_buffers/generators.rb', line 19

def get
  idx = @rng.rand(@range.size)
  @range[idx]
end

#range(range) ⇒ Object



14
15
16
17
# File 'lib/dbms_buffers/generators.rb', line 14

def range(range)
  @range = range.to_a
  self
end

#repeat(amount) ⇒ Object



24
25
26
27
28
# File 'lib/dbms_buffers/generators.rb', line 24

def repeat(amount)
  result = []
  amount.times { result << get }
  result
end