Class LcgRndInt31

java.lang.Object
io.github.olyutorskii.aletojio.rng.lcg.AbstractLcg
io.github.olyutorskii.aletojio.rng.lcg.LcgRndInt31
All Implemented Interfaces:
RndInt31

public class LcgRndInt31 extends AbstractLcg implements RndInt31
Implementation of 31bit output Linear congruential generator(LCG).

LCG is a commonly used random number generator in the past.

* LCG implementations on CPU without 64-bit remainders often output only 31-bit random numbers.

Recurrence relation sequences : X(n+1) = (X(n) * Mul + Inc) mod Mod

  • Mul : Multiplier
  • Inc : Increment
  • Mod : Modulus
See Also:
  • Constructor Details

    • LcgRndInt31

      public LcgRndInt31(long mulArg, long incArg, long modArg) throws IllegalArgumentException
      Constructor.
      • Multiplier must be 1 or greatrer.
      • Increment must be 0 or greatrer.
      • Modulus must be 2 or greater.
      Parameters:
      mulArg - multiplier
      incArg - increment
      modArg - modulus
      Throws:
      IllegalArgumentException - illegal argument
  • Method Details

    • seedToResult

      protected int seedToResult()
      Calculate result number from seed.

      result(31bit) reflects seed[0:30]

      Specified by:
      seedToResult in class AbstractLcg
      Returns:
      result number
    • nextInt31

      public int nextInt31()
      Return next random number as 31bit int from LSB without sign-bit.

      Only positive or zero value returned.

      * LCG implementations on CPU without 64-bit remainders often output only 31-bit random numbers.

      Specified by:
      nextInt31 in interface RndInt31
      Returns:
      random number