Class: DbmsBuffers::SimpleGenerator
- Inherits:
-
Object
- Object
- DbmsBuffers::SimpleGenerator
- 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
- #get ⇒ Object
-
#initialize(seed = Random.new_seed) ⇒ SimpleGenerator
constructor
A new instance of SimpleGenerator.
- #range(range) ⇒ Object
- #repeat(amount) ⇒ Object
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
#get ⇒ Object
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 |