java.lang.Object
io.github.olyutorskii.aletojio.rng.mwc.Mwc
io.github.olyutorskii.aletojio.rng.mwc.Cmwc
All Implemented Interfaces:
RndInt32

public class Cmwc extends Mwc
Complementary-multiply-with-carry random number generator.

Random sequence X(n) is derived as follows with parameter a(multiplier), b(divisor).

  • T(n) = a * X(n-r) + C(n-1)
  • C(n) = T(n) / b
  • Y(n) = T(n) mod b
  • X(n) = b - 1 - Y(n)

r is the length of the record that stores past results. "carry" comes from C(n-1).

See Also:
  • Constructor Details

    • Cmwc

      public Cmwc(int recLen, long mulArg, long divArg) throws IllegalArgumentException
      Constructor.
      • record length must be greater than 0.
      • multiplier must be greater than 1.
      • divisor must be greater than 1.

      If you want 32-bit uniformly distributed random numbers, the divisor must be 2**32, but you can compromise with 2**32 -1.

      Parameters:
      recLen - records length
      mulArg - multiplier
      divArg - divisor
      Throws:
      IllegalArgumentException - illegal argument
    • Cmwc

      public Cmwc() throws IllegalArgumentException
      Constructor.
      • Default record length = 1024
      • Default multiplier value = 987769338
      • Default divisor value = 2**32 - 1

      * Caution : If you don't provide your entropy to seeds, it takes over million trials until the seed is scrambled.

      Throws:
      IllegalArgumentException - illegal argument
      See Also:
  • Method Details

    • funcRndFromTval

      protected int funcRndFromTval(long tVal)
      Function that takes T-value as an argument and returns random result.
      Overrides:
      funcRndFromTval in class Mwc
      Parameters:
      tVal - T-value
      Returns:
      random result