// 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 LCG extends SimpleRNG {
   // parameters
   private int multiply;
   private int add;
   private int modulus;

   // state
   private int state;

   // constructor
   public LCG(int mu, int ad, int mo) {
      multiply = mu;
      add = ad;
      modulus = mo;
   }

   // interface
   public void init(int seed) {
      state = seed % modulus;
      return;
   }
   public int getMaxInt() {
      return modulus;
   }
   public int getInt() {
      state = (int)(((long)multiply * (long)state + (long)add) % (long)modulus);
      return state;
   }
}
