Class ISAACRandom

  • All Implemented Interfaces:
    RandomIntSource, RestorableUniformRandomProvider, UniformRandomProvider

    public class ISAACRandom
    extends IntProvider
    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:
    1.0
    See Also:
    ISAAC: a fast cryptographic pseudo-random number generator, ISAAC (Wikipedia)
    • Field Detail

      • SIZE_L

        private static final int SIZE_L
        Log of size of rsl[] and mem[].
        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​(int[] seed)
        Creates a new ISAAC random number generator.
        Parameters:
        seed - Initial seed
    • Method Detail

      • getStateInternal

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

        private void setSeedInternal​(int[] seed)
        Reseeds the RNG.
        Parameters:
        seed - Seed. Cannot be null.
      • next

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

        private void isaac()
        Generate 256 results.
      • isaac2

        private void isaac2()
        Intermediate internal loop.
      • isaac3

        private void isaac3()
        Lowest level internal loop.
      • initState

        private void initState()
        Initialize, or reinitialize, this instance of rand.
      • shuffle

        private void shuffle()
        Shuffle array.
      • setState

        private void setState​(int start)
        Set the state by copying the internal arrays.
        Parameters:
        start - First index into mem array.