Class TwoCmres

All Implemented Interfaces:
RandomLongSource, RestorableUniformRandomProvider, UniformRandomProvider

public class TwoCmres extends LongProvider
Random number generator designed by Mark D. Overton.

It is one of the many generators described by the author in the following article series:

Since:
1.0
  • Field Details

    • INTERNAL_ERROR_MSG

      private static final String INTERNAL_ERROR_MSG
      Error message.
      See Also:
    • SEED_GUARD

      private static final byte SEED_GUARD
      A small positive integer.
      See Also:
    • FACTORY

      private static final TwoCmres.Cmres.Factory FACTORY
      Factory of instances of this class. Singleton.
    • x

      private final TwoCmres.Cmres x
      First subcycle generator.
    • y

      private final TwoCmres.Cmres y
      Second subcycle generator.
    • xx

      private long xx
      State of first subcycle generator.
    • yy

      private long yy
      State of second subcycle generator.
  • Constructor Details

    • TwoCmres

      private TwoCmres(int seed, TwoCmres.Cmres x, TwoCmres.Cmres y)
      Creates a new instance.
      Parameters:
      seed - Initial seed.
      x - First subcycle generator.
      y - Second subcycle generator.
      Throws:
      IllegalArgumentException - if x == y.
    • TwoCmres

      public TwoCmres(Integer seed)
      Creates a new instance.
      Parameters:
      seed - Seed.
    • TwoCmres

      public TwoCmres(Integer seed, int i, int j)
      Creates a new instance.
      Parameters:
      seed - Seed.
      i - Table entry for first subcycle generator.
      j - Table entry for second subcycle generator.
      Throws:
      IllegalArgumentException - if i == j.
      IndexOutOfBoundsException - if i < 0 or i >= numberOfSubcycleGenerators().
      IndexOutOfBoundsException - if j < 0 or j >= numberOfSubcycleGenerators().
  • Method Details

    • next

      public long next()
      Returns:
      the next random value.
    • toString

      public String toString()
      Overrides:
      toString in class BaseProvider
    • numberOfSubcycleGenerators

      public static int numberOfSubcycleGenerators()
      Returns:
      the number of subcycle generators.
    • getStateInternal

      protected byte[] getStateInternal()
      Creates a snapshot of the RNG state.
      Overrides:
      getStateInternal in class LongProvider
      Returns:
      the internal state.
    • setStateInternal

      protected void setStateInternal(byte[] s)
      Resets the RNG to the given state.
      Overrides:
      setStateInternal in class LongProvider
      Parameters:
      s - State (previously obtained by a call to BaseProvider.getStateInternal()).
      See Also:
    • setSeedInternal

      private void setSeedInternal(int seed)
      Parameters:
      seed - Seed.