class SubRandom
  
  attr_reader :seed

  
  
  def initialize(seed = Kernel.rand(1_000_000_000))
    (0..999_999_999).include? seed or
      raise ArgumentError, 

    
    ary = [seed, 1]
    53.times { ary << ary[-2] - ary[-1] }
    @state = []
    34.step(1870, 34) {|i| @state << ary[i % 55] }

    220.times { rand }  

    @seed = seed        
  end

  
  def initialize_copy(orig)
    @state = @state.dup
  end

  
  def rand
    @state << (@state[-55] - @state[-24]) % 1_000_000_000
    @state.shift
  end
end

rng = SubRandom.new(292929)
p (1..3).map { rng.rand }