// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.util.Vector;

//
// CMRG algorithm
// L'Ecuyer Operations Research 1996
// cycle = 10^61
//

public class CMRG extends CombinedRNG implements Combiner {
   private final static int[] mul1 = { 0, 63308, -183326};
   private final static int[] mul2 = { 86098, 0, -539608};

   // constructor
   public CMRG() {
      super();
      Vector gen = new Vector();
      gen.add(new MRG(mul1, 2147483647));
      gen.add(new MRG(mul2, 2145483479));
      setGenerators(gen);
      setCombine(this);
   }

   // interface
   public double getDouble(Vector gen) {
      int res = ((RNG)gen.get(0)).getInt() - ((RNG)gen.get(1)).getInt();
      if(res < 0) res = res + 2147483647;
      return (res / 2147483648.0);
   }
}
