Package org.apache.commons.rng
Class UniformRandomProviderSupport
- java.lang.Object
-
- org.apache.commons.rng.UniformRandomProviderSupport
-
final class UniformRandomProviderSupport extends java.lang.ObjectSupport forUniformRandomProviderdefault methods.- Since:
- 1.5
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classUniformRandomProviderSupport.ProviderDoublesSpliteratorSpliterator for streams of double values that may be recursively split.(package private) static classUniformRandomProviderSupport.ProviderIntsSpliteratorSpliterator for streams of int values that may be recursively split.(package private) static classUniformRandomProviderSupport.ProviderLongsSpliteratorSpliterator for streams of long values that may be recursively split.private static classUniformRandomProviderSupport.ProviderSpliteratorBase class for spliterators for streams of values.(package private) static classUniformRandomProviderSupport.ProviderSplitsSpliteratorSpliterator for streams of SplittableUniformRandomProvider.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringINVALID_RANGEMessage format for an invalid range for lower inclusive and upper exclusive.private static java.lang.StringINVALID_STREAM_SIZEMessage for an invalid stream size.private static java.lang.StringINVALID_UPPER_BOUNDMessage for an invalid upper bound (must be positive, finite and above zero).private static java.lang.StringNULL_ACTIONMessage when the consumer action is null.private static longPOW_322^32.
-
Constructor Summary
Constructors Modifier Constructor Description privateUniformRandomProviderSupport()No instances.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description (package private) static voidnextBytes(UniformRandomProvider source, byte[] bytes, int start, int len)Generates random bytes and places them into a user-supplied array.(package private) static doublenextDouble(UniformRandomProvider source, double bound)Generates adoublevalue between 0 (inclusive) and the specified value (exclusive).(package private) static doublenextDouble(UniformRandomProvider source, double origin, double bound)Generates adoublevalue between the specifiedorigin(inclusive) and the specifiedbound(exclusive).(package private) static floatnextFloat(UniformRandomProvider source, float bound)Generates afloatvalue between 0 (inclusive) and the specified value (exclusive).(package private) static floatnextFloat(UniformRandomProvider source, float origin, float bound)Generates afloatvalue between the specifiedorigin(inclusive) and the specifiedbound(exclusive).(package private) static intnextInt(UniformRandomProvider source, int n)Generates anintvalue between 0 (inclusive) and the specified value (exclusive).(package private) static intnextInt(UniformRandomProvider source, int origin, int bound)Generates anintvalue between the specifiedorigin(inclusive) and the specifiedbound(exclusive).(package private) static longnextLong(UniformRandomProvider source, long n)Generates anlongvalue between 0 (inclusive) and the specified value (exclusive).(package private) static longnextLong(UniformRandomProvider source, long origin, long bound)Generates alongvalue between the specifiedorigin(inclusive) and the specifiedbound(exclusive).(package private) static voidvalidateFromIndexSize(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 voidvalidateRange(double origin, double bound)Validate the range between the specifiedorigin(inclusive) and the specifiedbound(exclusive).(package private) static voidvalidateRange(int origin, int bound)Validate the range between the specifiedorigin(inclusive) and the specifiedbound(exclusive).(package private) static voidvalidateRange(long origin, long bound)Validate the range between the specifiedorigin(inclusive) and the specifiedbound(exclusive).(package private) static voidvalidateStreamSize(long size)Validate the stream size.(package private) static voidvalidateUpperBound(double bound)Validate the upper bound.(package private) static voidvalidateUpperBound(float bound)Validate the upper bound.(package private) static voidvalidateUpperBound(int bound)Validate the upper bound.(package private) static voidvalidateUpperBound(long bound)Validate the upper bound.
-
-
-
Field Detail
-
INVALID_STREAM_SIZE
private static final java.lang.String INVALID_STREAM_SIZE
Message for an invalid stream size.- See Also:
- Constant Field Values
-
INVALID_UPPER_BOUND
private static final java.lang.String INVALID_UPPER_BOUND
Message for an invalid upper bound (must be positive, finite and above zero).- See Also:
- Constant Field Values
-
INVALID_RANGE
private static final java.lang.String INVALID_RANGE
Message format for an invalid range for lower inclusive and upper exclusive.- See Also:
- Constant Field Values
-
POW_32
private static final long POW_32
2^32.- See Also:
- Constant Field Values
-
NULL_ACTION
private static final java.lang.String NULL_ACTION
Message when the consumer action is null.- See Also:
- Constant Field Values
-
-
Method Detail
-
validateStreamSize
static void validateStreamSize(long size)
Validate the stream size.- Parameters:
size- Stream size.- Throws:
java.lang.IllegalArgumentException- ifsizeis negative.
-
validateUpperBound
static void validateUpperBound(int bound)
Validate the upper bound.- Parameters:
bound- Upper bound (exclusive) on the random number to be returned.- Throws:
java.lang.IllegalArgumentException- ifboundis 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:
java.lang.IllegalArgumentException- ifboundis 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:
java.lang.IllegalArgumentException- ifboundis 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:
java.lang.IllegalArgumentException- ifboundis equal to or less than zero, or is not finite
-
validateRange
static void validateRange(int origin, int bound)Validate the range between the specifiedorigin(inclusive) and the specifiedbound(exclusive).- Parameters:
origin- Lower bound on the random number to be returned.bound- Upper bound (exclusive) on the random number to be returned.- Throws:
java.lang.IllegalArgumentException- iforiginis greater than or equal tobound.
-
validateRange
static void validateRange(long origin, long bound)Validate the range between the specifiedorigin(inclusive) and the specifiedbound(exclusive).- Parameters:
origin- Lower bound on the random number to be returned.bound- Upper bound (exclusive) on the random number to be returned.- Throws:
java.lang.IllegalArgumentException- iforiginis greater than or equal tobound.
-
validateRange
static void validateRange(double origin, double bound)Validate the range between the specifiedorigin(inclusive) and the specifiedbound(exclusive).- Parameters:
origin- Lower bound on the random number to be returned.bound- Upper bound (exclusive) on the random number to be returned.- Throws:
java.lang.IllegalArgumentException- iforiginis not finite, orboundis not finite, ororiginis greater than or equal tobound.
-
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.checkFromIndexSizeintroduced 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 < 0size < 0fromIndex + size > length, taking into account integer overflowlength < 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 < 0as this is assumed to be derived from an array length.
- Parameters:
fromIndex- the lower-bound (inclusive) of the sub-intervalsize- the size of the sub-rangelength- the upper-bound (exclusive) of the range- Throws:
java.lang.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
longvalues. 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 anintvalue 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
intvalue between 0 (inclusive) andn(exclusive).
-
nextInt
static int nextInt(UniformRandomProvider source, int origin, int bound)
Generates anintvalue between the specifiedorigin(inclusive) and the specifiedbound(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 aboveorigin.- Returns:
- a random
intvalue betweenorigin(inclusive) andbound(exclusive).
-
nextLong
static long nextLong(UniformRandomProvider source, long n)
Generates anlongvalue 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
longvalue between 0 (inclusive) andn(exclusive).
-
nextLong
static long nextLong(UniformRandomProvider source, long origin, long bound)
Generates alongvalue between the specifiedorigin(inclusive) and the specifiedbound(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 aboveorigin.- Returns:
- a random
longvalue betweenorigin(inclusive) andbound(exclusive).
-
nextFloat
static float nextFloat(UniformRandomProvider source, float bound)
Generates afloatvalue 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
floatvalue between 0 (inclusive) andbound(exclusive).
-
nextFloat
static float nextFloat(UniformRandomProvider source, float origin, float bound)
Generates afloatvalue between the specifiedorigin(inclusive) and the specifiedbound(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 aboveoriginand finite.- Returns:
- a random
floatvalue betweenorigin(inclusive) andbound(exclusive).
-
nextDouble
static double nextDouble(UniformRandomProvider source, double bound)
Generates adoublevalue 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
doublevalue between 0 (inclusive) andbound(exclusive).
-
nextDouble
static double nextDouble(UniformRandomProvider source, double origin, double bound)
Generates adoublevalue between the specifiedorigin(inclusive) and the specifiedbound(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 aboveoriginand finite.- Returns:
- a random
doublevalue betweenorigin(inclusive) andbound(exclusive).
-
-