Class Java2Random

    • Constructor Detail

      • Java2Random

        public Java2Random()
        Create a new Java2Random and initializes with System.currentTimeMillis.
      • Java2Random

        public Java2Random​(long seed)
        Create a new Java2Random and initialize with a given seed.
        Parameters:
        seed - long; the seed to use.
    • Method Detail

      • reset

        public void reset()
        Reset the stream to use the original seed with which it was initialized.
        Specified by:
        reset in interface StreamInterface
      • getOriginalSeed

        public long getOriginalSeed()
        Return the original seed of the generator with which it has been first initialized.
        Specified by:
        getOriginalSeed in interface StreamInterface
        Returns:
        long; the original seed of the generator when it was first initialized
      • nextInt

        public int nextInt​(int i,
                           int j)
        Return pseudo-random number from the stream between the integers i (inclusive) and j (inclusive).
        Specified by:
        nextInt in interface StreamInterface
        Parameters:
        i - int; the minimal value
        j - int; the maximum value
        Returns:
        int; a value between i and j
      • setSeed

        public void setSeed​(long seed)
        Set the seed of the generator.
        Specified by:
        setSeed in interface StreamInterface
        Overrides:
        setSeed in class Random
        Parameters:
        seed - long; the new seed
      • getSeed

        public long getSeed()
        Return the seed of the generator.
        Specified by:
        getSeed in interface StreamInterface
        Returns:
        long; the seed
      • saveState

        public byte[] saveState()
                         throws StreamException
        Save the state of the RNG into an object, e.g. to roll it back to this state.
        Specified by:
        saveState in interface StreamInterface
        Returns:
        the state as an object specific to the RNG.
        Throws:
        StreamException - when getting the state fails.
      • restoreState

        public void restoreState​(byte[] state)
                          throws StreamException
        Restore the state to an earlier saved state object.
        Specified by:
        restoreState in interface StreamInterface
        Parameters:
        state - Object; the earlier saved state to which the RNG rolls back.
        Throws:
        StreamException - when resetting the state fails.