Class UniformRandomProviderSupport

java.lang.Object
org.apache.commons.rng.UniformRandomProviderSupport

final class UniformRandomProviderSupport extends Object
Support for UniformRandomProvider default methods.
Since:
1.5
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    (package private) static class 
    Spliterator for streams of double values that may be recursively split.
    (package private) static class 
    Spliterator for streams of int values that may be recursively split.
    (package private) static class 
    Spliterator for streams of long values that may be recursively split.
    private static class 
    Base class for spliterators for streams of values.
    (package private) static class 
    Spliterator for streams of SplittableUniformRandomProvider.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    Message format for an invalid range for lower inclusive and upper exclusive.
    private static final String
    Message for an invalid stream size.
    private static final String
    Message for an invalid upper bound (must be positive, finite and above zero).
    private static final String
    Message when the consumer action is null.
    private static final long
    2^32.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    No instances.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static void
    nextBytes(UniformRandomProvider source, byte[] bytes, int start, int len)
    Generates random bytes and places them into a user-supplied array.
    (package private) static double
    nextDouble(UniformRandomProvider source, double bound)
    Generates a double value between 0 (inclusive) and the specified value (exclusive).
    (package private) static double
    nextDouble(UniformRandomProvider source, double origin, double bound)
    Generates a double value between the specified origin (inclusive) and the specified bound (exclusive).
    (package private) static float
    nextFloat(UniformRandomProvider source, float bound)
    Generates a float value between 0 (inclusive) and the specified value (exclusive).
    (package private) static float
    nextFloat(UniformRandomProvider source, float origin, float bound)
    Generates a float value between the specified origin (inclusive) and the specified bound (exclusive).
    (package private) static int
    Generates an int value between 0 (inclusive) and the specified value (exclusive).
    (package private) static int
    nextInt(UniformRandomProvider source, int origin, int bound)
    Generates an int value between the specified origin (inclusive) and the specified bound (exclusive).
    (package private) static long
    Generates an long value between 0 (inclusive) and the specified value (exclusive).
    (package private) static long
    nextLong(UniformRandomProvider source, long origin, long bound)
    Generates a long value between the specified origin (inclusive) and the specified bound (exclusive).
    (package private) static void
    validateFromIndexSize(int fromIndex, int size, int length)
    Checks if the sub-range from fromIndex (inclusive) to fromIndex + size (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).
    (package private) static void
    validateRange(double origin, double bound)
    Validate the range between the specified origin (inclusive) and the specified bound (exclusive).
    (package private) static void
    validateRange(int origin, int bound)
    Validate the range between the specified origin (inclusive) and the specified bound (exclusive).
    (package private) static void
    validateRange(long origin, long bound)
    Validate the range between the specified origin (inclusive) and the specified bound (exclusive).
    (package private) static void
    validateStreamSize(long size)
    Validate the stream size.
    (package private) static void
    validateUpperBound(double bound)
    Validate the upper bound.
    (package private) static void
    validateUpperBound(float bound)
    Validate the upper bound.
    (package private) static void
    validateUpperBound(int bound)
    Validate the upper bound.
    (package private) static void
    validateUpperBound(long bound)
    Validate the upper bound.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INVALID_STREAM_SIZE

      private static final String INVALID_STREAM_SIZE
      Message for an invalid stream size.
      See Also:
    • INVALID_UPPER_BOUND

      private static final String INVALID_UPPER_BOUND
      Message for an invalid upper bound (must be positive, finite and above zero).
      See Also:
    • INVALID_RANGE

      private static final String INVALID_RANGE
      Message format for an invalid range for lower inclusive and upper exclusive.
      See Also:
    • POW_32

      private static final long POW_32
      2^32.
      See Also:
    • NULL_ACTION

      private static final String NULL_ACTION
      Message when the consumer action is null.
      See Also:
  • Constructor Details

    • UniformRandomProviderSupport

      private UniformRandomProviderSupport()
      No instances.
  • Method Details

    • validateStreamSize

      static void validateStreamSize(long size)
      Validate the stream size.
      Parameters:
      size - Stream size.
      Throws:
      IllegalArgumentException - if size is negative.
    • validateUpperBound

      static void validateUpperBound(int bound)
      Validate the upper bound.
      Parameters:
      bound - Upper bound (exclusive) on the random number to be returned.
      Throws:
      IllegalArgumentException - if bound is equal to or less than zero.
    • validateUpperBound

      static void validateUpperBound(long bound)
      Validate the upper bound.
      Parameters:
      bound - Upper bound (exclusive) on the random number to be returned.
      Throws:
      IllegalArgumentException - if bound is equal to or less than zero.
    • validateUpperBound

      static void validateUpperBound(float bound)
      Validate the upper bound.
      Parameters:
      bound - Upper bound (exclusive) on the random number to be returned.
      Throws:
      IllegalArgumentException - if bound is equal to or less than zero, or is not finite
    • validateUpperBound

      static void validateUpperBound(double bound)
      Validate the upper bound.
      Parameters:
      bound - Upper bound (exclusive) on the random number to be returned.
      Throws:
      IllegalArgumentException - if bound is equal to or less than zero, or is not finite
    • validateRange

      static void validateRange(int origin, int bound)
      Validate the range between the specified origin (inclusive) and the specified bound (exclusive).
      Parameters:
      origin - Lower bound on the random number to be returned.
      bound - Upper bound (exclusive) on the random number to be returned.
      Throws:
      IllegalArgumentException - if origin is greater than or equal to bound.
    • validateRange

      static void validateRange(long origin, long bound)
      Validate the range between the specified origin (inclusive) and the specified bound (exclusive).
      Parameters:
      origin - Lower bound on the random number to be returned.
      bound - Upper bound (exclusive) on the random number to be returned.
      Throws:
      IllegalArgumentException - if origin is greater than or equal to bound.
    • validateRange

      static void validateRange(double origin, double bound)
      Validate the range between the specified origin (inclusive) and the specified bound (exclusive).
      Parameters:
      origin - Lower bound on the random number to be returned.
      bound - Upper bound (exclusive) on the random number to be returned.
      Throws:
      IllegalArgumentException - if origin is not finite, or bound is not finite, or origin is greater than or equal to bound.
    • validateFromIndexSize

      static void validateFromIndexSize(int fromIndex, int size, int length)
      Checks if the sub-range from fromIndex (inclusive) to fromIndex + size (exclusive) is within the bounds of range from 0 (inclusive) to length (exclusive).

      This function provides the functionality of java.utils.Objects.checkFromIndexSize introduced in JDK 9. The Objects javadoc has been reproduced for reference.

      The sub-range is defined to be out of bounds if any of the following inequalities is true:

      • fromIndex < 0
      • size < 0
      • fromIndex + size > length, taking into account integer overflow
      • length < 0, which is implied from the former inequalities

      Note: This is not an exact implementation of the functionality of Objects.checkFromIndexSize. The following changes have been made:

      • The method signature has been changed to avoid the return of fromIndex; this value is not used within this package.
      • No checks are made for length < 0 as this is assumed to be derived from an array length.
      Parameters:
      fromIndex - the lower-bound (inclusive) of the sub-interval
      size - the size of the sub-range
      length - the upper-bound (exclusive) of the range
      Throws:
      IndexOutOfBoundsException - if the sub-range is out of bounds
    • nextBytes

      static void nextBytes(UniformRandomProvider source, byte[] bytes, int start, int len)
      Generates random bytes and places them into a user-supplied array.

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

      Parameters:
      source - Source of randomness.
      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.
    • nextInt

      static int nextInt(UniformRandomProvider source, int n)
      Generates an int value between 0 (inclusive) and the specified value (exclusive).
      Parameters:
      source - Source of randomness.
      n - Bound on the random number to be returned. Must be strictly positive.
      Returns:
      a random int value between 0 (inclusive) and n (exclusive).
    • nextInt

      static int nextInt(UniformRandomProvider source, int origin, int bound)
      Generates an int value between the specified origin (inclusive) and the specified bound (exclusive).
      Parameters:
      source - Source of randomness.
      origin - Lower bound on the random number to be returned.
      bound - Upper bound (exclusive) on the random number to be returned. Must be above origin.
      Returns:
      a random int value between origin (inclusive) and bound (exclusive).
    • nextLong

      static long nextLong(UniformRandomProvider source, long n)
      Generates an long value between 0 (inclusive) and the specified value (exclusive).
      Parameters:
      source - Source of randomness.
      n - Bound on the random number to be returned. Must be strictly positive.
      Returns:
      a random long value between 0 (inclusive) and n (exclusive).
    • nextLong

      static long nextLong(UniformRandomProvider source, long origin, long bound)
      Generates a long value between the specified origin (inclusive) and the specified bound (exclusive).
      Parameters:
      source - Source of randomness.
      origin - Lower bound on the random number to be returned.
      bound - Upper bound (exclusive) on the random number to be returned. Must be above origin.
      Returns:
      a random long value between origin (inclusive) and bound (exclusive).
    • nextFloat

      static float nextFloat(UniformRandomProvider source, float bound)
      Generates a float value between 0 (inclusive) and the specified value (exclusive).
      Parameters:
      source - Source of randomness.
      bound - Bound on the random number to be returned. Must be strictly positive.
      Returns:
      a random float value between 0 (inclusive) and bound (exclusive).
    • nextFloat

      static float nextFloat(UniformRandomProvider source, float origin, float bound)
      Generates a float value between the specified origin (inclusive) and the specified bound (exclusive).
      Parameters:
      source - Source of randomness.
      origin - Lower bound on the random number to be returned. Must be finite.
      bound - Upper bound (exclusive) on the random number to be returned. Must be above origin and finite.
      Returns:
      a random float value between origin (inclusive) and bound (exclusive).
    • nextDouble

      static double nextDouble(UniformRandomProvider source, double bound)
      Generates a double value between 0 (inclusive) and the specified value (exclusive).
      Parameters:
      source - Source of randomness.
      bound - Bound on the random number to be returned. Must be strictly positive.
      Returns:
      a random double value between 0 (inclusive) and bound (exclusive).
    • nextDouble

      static double nextDouble(UniformRandomProvider source, double origin, double bound)
      Generates a double value between the specified origin (inclusive) and the specified bound (exclusive).
      Parameters:
      source - Source of randomness.
      origin - Lower bound on the random number to be returned. Must be finite.
      bound - Upper bound (exclusive) on the random number to be returned. Must be above origin and finite.
      Returns:
      a random double value between origin (inclusive) and bound (exclusive).