Class KISSRandom

All Implemented Interfaces:
RandomIntSource, RestorableUniformRandomProvider, UniformRandomProvider

public class KISSRandom extends IntProvider
Port from Marsaglia's "KISS" algorithm. This version contains the correction referred to here in a reply to the original post.
Since:
1.0
See Also:
  • Field Details

    • SEED_SIZE

      private static final int SEED_SIZE
      Size of the seed.
      See Also:
    • z

      private int z
      State variable.
    • w

      private int w
      State variable.
    • jsr

      private int jsr
      State variable.
    • jcong

      private int jcong
      State variable.
  • Constructor Details

    • KISSRandom

      public KISSRandom(int[] seed)
      Creates a new instance.
      Parameters:
      seed - Seed. If the length is larger than 4, only the first 4 elements will be used; if smaller, the remaining elements will be automatically set.
  • Method Details

    • getStateInternal

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

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

      private void setSeedInternal(int[] seed)
      Seeds the RNG.
      Parameters:
      seed - Seed.
    • next

      public int next()
      Return the next random value.
      Returns:
      the next random value.
    • computeNew

      private static int computeNew(int mult, int previous)
      Compute new value.
      Parameters:
      mult - Multiplier.
      previous - Previous value.
      Returns:
      new value.