Class UniformRandomProviderSupport
java.lang.Object
org.apache.commons.rng.UniformRandomProviderSupport
Support for
UniformRandomProvider default methods.- Since:
- 1.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classSpliterator for streams of double values that may be recursively split.(package private) static classSpliterator for streams of int values that may be recursively split.(package private) static classSpliterator for streams of long values that may be recursively split.private static classBase class for spliterators for streams of values.(package private) static classSpliterator for streams of SplittableUniformRandomProvider. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final StringMessage format for an invalid range for lower inclusive and upper exclusive.private static final StringMessage for an invalid stream size.private static final StringMessage for an invalid upper bound (must be positive, finite and above zero).private static final StringMessage when the consumer action is null.private static final long2^32. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(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 Details
-
INVALID_STREAM_SIZE
-
INVALID_UPPER_BOUND
Message for an invalid upper bound (must be positive, finite and above zero).- See Also:
-
INVALID_RANGE
Message format for an invalid range for lower inclusive and upper exclusive.- See Also:
-
POW_32
private static final long POW_322^32.- See Also:
-
NULL_ACTION
-
-
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- 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:
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:
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:
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:
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:
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:
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:
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:
IndexOutOfBoundsException- if the sub-range is out of bounds
-
nextBytes
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
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
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
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
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
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
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
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
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).
-