Class IntProvider

java.lang.Object
org.apache.commons.rng.core.BaseProvider
org.apache.commons.rng.core.source32.IntProvider
All Implemented Interfaces:
RandomIntSource, RestorableUniformRandomProvider, UniformRandomProvider
Direct Known Subclasses:
AbstractWell, DotyHumphreySmallFastCounting32, ISAACRandom, JDKRandom, JenkinsSmallFast32, KISSRandom, L32X64Mix, MersenneTwister, MiddleSquareWeylSequence, MultiplyWithCarry256, PcgMcgXshRr32, PcgMcgXshRs32, PcgXshRr32, PcgXshRs32, XoRoShiRo64Star, XoRoShiRo64StarStar, XoShiRo128Plus, XoShiRo128PlusPlus, XoShiRo128StarStar

public abstract class IntProvider extends BaseProvider implements RandomIntSource
Base class for all implementations that provide an int-based source randomness.
  • Constructor Details

    • IntProvider

      public IntProvider()
      Creates a new instance.
    • IntProvider

      protected IntProvider(IntProvider source)
      Creates a new instance copying the state from the source.

      This provides base functionality to allow a generator to create a copy, for example for use in the JumpableUniformRandomProvider interface.

      Parameters:
      source - Source to copy.
      Since:
      1.3
  • Method Details

    • resetCachedState

      protected void resetCachedState()
      Reset the cached state used in the default implementation of nextBoolean().

      This should be used when the state is no longer valid, for example after a jump performed for the JumpableUniformRandomProvider interface.

      Since:
      1.3
    • getStateInternal

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

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

      public int nextInt()
      Generates an int value.
      Specified by:
      nextInt in interface UniformRandomProvider
      Returns:
      the next random value.
    • nextBoolean

      public boolean nextBoolean()
      Generates a boolean value.
      Specified by:
      nextBoolean in interface UniformRandomProvider
      Returns:
      the next random value.
    • nextDouble

      public double nextDouble()
      Generates a double value between 0 (inclusive) and 1 (exclusive).
      Specified by:
      nextDouble in interface UniformRandomProvider
      Returns:
      the next random value between 0 (inclusive) and 1 (exclusive).
    • nextLong

      public long nextLong()
      Generates a long value.
      Specified by:
      nextLong in interface UniformRandomProvider
      Returns:
      the next random value.
    • nextBytes

      public void nextBytes(byte[] bytes)
      Generates byte values and places them into a user-supplied array.

      The number of random bytes produced is equal to the length of the byte array.

      Specified by:
      nextBytes in interface UniformRandomProvider
      Parameters:
      bytes - Byte array in which to put the random bytes. Cannot be null.
    • nextBytes

      public void nextBytes(byte[] bytes, int start, int len)
      Generates byte values and places them into a user-supplied array.

      The array is filled with bytes extracted from random integers. This implies that the number of random bytes generated may be larger than the length of the byte array.

      Specified by:
      nextBytes in interface UniformRandomProvider
      Parameters:
      bytes - Array in which to put the generated bytes. Cannot be null.
      start - Index at which to start inserting the generated bytes.
      len - Number of bytes to insert.