Class ISAACRandom

  • All Implemented Interfaces:
    java.io.Serializable, RandomGenerator

    public class ISAACRandom
    extends BitsStreamGenerator
    implements java.io.Serializable
    ISAAC: a fast cryptographic pseudo-random number generator
    ISAAC (Indirection, Shift, Accumulate, Add, and Count) generates 32-bit random numbers. ISAAC has been designed to be cryptographically secure and is inspired by RC4. Cycles are guaranteed to be at least 240 values long, and they are 28295 values long on average. The results are uniformly distributed, unbiased, and unpredictable unless you know the seed.
    This code is based (with minor changes and improvements) on the original implementation of the algorithm by Bob Jenkins.
    Since:
    3.0
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int[] arr
      Service variable.
      private int count
      Count through the results in rsl[]
      private static int GLD_RATIO
      The golden ratio
      private static int H_SIZE
      Half-size of rsl[] and mem[]
      private int isaacA
      Accumulator
      private int isaacB
      The last result
      private int isaacC
      Counter, guarantees cycle is at least 2^40
      private int isaacI
      Service variable.
      private int isaacJ
      Service variable.
      private int isaacX
      Service variable.
      private static int MASK
      For pseudo-random lookup
      private int[] mem
      The internal state
      private int[] rsl
      The results given to the user
      private static long serialVersionUID
      Serializable version identifier
      private static int SIZE
      Size of rsl[] and mem[]
      private static int SIZE_L
      Log of size of rsl[] and mem[]
    • Constructor Summary

      Constructors 
      Constructor Description
      ISAACRandom()
      Creates a new ISAAC random number generator.
      ISAACRandom​(int[] seed)
      Creates a new ISAAC random number generator using an int array seed.
      ISAACRandom​(long seed)
      Creates a new ISAAC random number generator using a single long seed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void initState()
      Initialize, or reinitialize, this instance of rand.
      private void isaac()
      Generate 256 results
      private void isaac2()
      Intermediate internal loop.
      private void isaac3()
      Lowest level internal loop.
      protected int next​(int bits)
      Generate next pseudorandom number.
      void setSeed​(int seed)
      Sets the seed of the underlying random number generator using an int seed.
      void setSeed​(int[] seed)
      Sets the seed of the underlying random number generator using an int array seed.
      void setSeed​(long seed)
      Sets the seed of the underlying random number generator using a long seed.
      private void setState​(int start)
      Set the state by copying the internal arrays.
      private void shuffle()
      Shuffle array.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        Serializable version identifier
        See Also:
        Constant Field Values
      • rsl

        private final int[] rsl
        The results given to the user
      • mem

        private final int[] mem
        The internal state
      • count

        private int count
        Count through the results in rsl[]
      • isaacA

        private int isaacA
        Accumulator
      • isaacB

        private int isaacB
        The last result
      • isaacC

        private int isaacC
        Counter, guarantees cycle is at least 2^40
      • arr

        private final int[] arr
        Service variable.
      • isaacX

        private int isaacX
        Service variable.
      • isaacI

        private int isaacI
        Service variable.
      • isaacJ

        private int isaacJ
        Service variable.
    • Constructor Detail

      • ISAACRandom

        public ISAACRandom()
        Creates a new ISAAC random number generator.
        The instance is initialized using a combination of the current time and system hash code of the instance as the seed.
      • ISAACRandom

        public ISAACRandom​(long seed)
        Creates a new ISAAC random number generator using a single long seed.
        Parameters:
        seed - Initial seed.
      • ISAACRandom

        public ISAACRandom​(int[] seed)
        Creates a new ISAAC random number generator using an int array seed.
        Parameters:
        seed - Initial seed. If null, the seed will be related to the current time.