module LCG
  module Common
    
    attr_reader :seed

    
    def initialize(seed)
      @seed = @r = seed
    end
  end

  
  
  class Berkeley
    include Common
    def rand
      @r = (1103515245 * @r + 12345) & 0x7fff_ffff
    end
  end

  
  
  class Microsoft
    include Common
    def rand
      @r = (214013 * @r + 2531011) & 0x7fff_ffff
      @r >> 16
    end
  end
end