Refactoring random number generation
The code:

def nice_numbers
  ([rand(9),rand(9)]*2).join
end


generates the same output as your function. It is also faster, as it does not test then regenerate anything.

If you want to DRY this up for rand(9):

def nice_numbers
  (Array.new(2) {rand(9)} * 2).join
end


Ruby language features used in this last example:


Array constructor takes a size param and a block to fill the Array
Multiplying an array by an integer repeats the array