Class LcgRndInt32

java.lang.Object
io.github.olyutorskii.aletojio.rng.lcg.AbstractLcg
io.github.olyutorskii.aletojio.rng.lcg.LcgRndInt32
All Implemented Interfaces:
RndInt32

public class LcgRndInt32 extends AbstractLcg implements RndInt32
Implementation of 32bit output Linear congruential generator(LCG).

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

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

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

    • LcgRndInt32

      public LcgRndInt32(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(32bit) reflects seed[16:47]

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

      public int nextInt32()
      Return next random number as 32bit int with random sign-bit.
      Specified by:
      nextInt32 in interface RndInt32
      Returns:
      random number