Sha256: 055ac6ca4321831855d063a2f073cf2cb5497842cc43fe203ca4a17731c38601
Contents?: true
Size: 866 Bytes
Versions: 2
Compression:
Stored size: 866 Bytes
Contents
module Stroop class ColorGenerator COLORS = %w{ black white red green blue yellow }.freeze attr_reader :seed def initialize(seed: nil) @seed = seed || Random.new_seed @single_random = Random.new(@seed) @pair_random = Random.new(@seed) end def generate selected = random_select(@single_random) while selected == @last_generated do selected = random_select(@single_random) end @last_generated = selected end def generate_pair first = generate second = random_select(@pair_random) while first == second || second == @last_generated_second do second = random_select(@pair_random) end @last_generated_second = second [first, second] end private def random_select(random) COLORS.sample(random: random) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stroop-1.2.0 | lib/stroop/color_generator.rb |
stroop-1.1.0 | lib/stroop/color_generator.rb |