Class LongProvider

java.lang.Object
org.apache.commons.rng.core.BaseProvider
org.apache.commons.rng.core.source64.LongProvider
All Implemented Interfaces:
RandomLongSource, RestorableUniformRandomProvider, UniformRandomProvider
Direct Known Subclasses:
MersenneTwister64, SplitMix64, TwoCmres, XoRoShiRo128Plus, XoRoShiRo128StarStar, XorShift1024Star, XoShiRo256Plus, XoShiRo256StarStar, XoShiRo512Plus, XoShiRo512StarStar

public abstract class LongProvider
extends BaseProvider
implements RandomLongSource
Base class for all implementations that provide a long-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)
    • nextLong

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

      public int nextInt()
      Generates an int value.
      Specified by:
      nextInt 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.
    • nextBoolean

      public boolean nextBoolean()
      Generates a boolean value.
      Specified by:
      nextBoolean in interface UniformRandomProvider
      Returns:
      the next random value.
    • 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.
    • 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.