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, ISAACRandom, JDKRandom, KISSRandom, MersenneTwister, MultiplyWithCarry256, XoRoShiRo64Star, XoRoShiRo64StarStar, XoShiRo128Plus, XoShiRo128StarStar

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

  • Method Details

    • 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:
      BaseProvider.checkStateSize(byte[],int)
    • 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 and 1.
      Specified by:
      nextDouble in interface UniformRandomProvider
      Returns:
      the next random value between 0 and 1.
    • nextFloat

      public float nextFloat()
      Generates a float value between 0 and 1.
      Specified by:
      nextFloat in interface UniformRandomProvider
      Returns:
      the next random value between 0 and 1.
    • 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 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.