// 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) 
public class MRG extends SimpleRNG {
   // parameters
   private int[] multiply;
   private int modulus;

   // state
   private int[] state;

   // constructor
   public MRG(int[] mu, int mo) {
      multiply = mu;
      modulus = mo;
      state = new int[mu.length];
   }

   // interface
   public void init(int seed) {
      for(int i = 0; i < state.length; i++) state[i] = seed % modulus;
      return;
   }
   public int getMaxInt() {
      return modulus;
   }
   public int getInt() {
      long tmp = 0;
      for(int i = 0; i < state.length; i++) tmp += (long)multiply[i] * (long)state[i];
      for(int i = 0; i < (state.length - 1); i++) state[i + 1] = state[i];
      state[0] = (int)(tmp % modulus);
      return state[0];
   }
}
