This is a permutation with repetition. Arrays can do this out of the box.
chars = %w(0 1 2 BC) sequencer = chars.repeated_permutation(chars.size) #OP:replace chars.size by 8 10.times{p sequencer.next} #["0", "0", "0", "0", "0"] #["0", "0", "0", "0", "1"] #["0", "0", "0", "0", "2"] #["0", "0", "0", "0", "B"] #["0", "0", "0", "0", "C"] #["0", "0", "0", "1", "0"] #["0", "0", "0", "1", "1"] #["0", "0", "0", "1", "2"] #["0", "0", "0", "1", "B"] #["0", "0", "0", "1", "C"] p sequencer.next #["0", "0", "0", "2", "0"]