Package org.apache.commons.rng
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 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
FieldsModifier and TypeFieldDescriptionprivate 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 -
Method Summary
Modifier and TypeMethodDescription(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 adouble
value between 0 (inclusive) and the specified value (exclusive).(package private) static double
nextDouble
(UniformRandomProvider source, double origin, double bound) Generates adouble
value between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).(package private) static float
nextFloat
(UniformRandomProvider source, float bound) Generates afloat
value between 0 (inclusive) and the specified value (exclusive).(package private) static float
nextFloat
(UniformRandomProvider source, float origin, float bound) Generates afloat
value between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).(package private) static int
nextInt
(UniformRandomProvider source, int n) Generates anint
value between 0 (inclusive) and the specified value (exclusive).(package private) static int
nextInt
(UniformRandomProvider source, int origin, int bound) Generates anint
value between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).(package private) static long
nextLong
(UniformRandomProvider source, long n) Generates anlong
value between 0 (inclusive) and the specified value (exclusive).(package private) static long
nextLong
(UniformRandomProvider source, long origin, long bound) Generates along
value between the specifiedorigin
(inclusive) and the specifiedbound
(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 specifiedorigin
(inclusive) and the specifiedbound
(exclusive).(package private) static void
validateRange
(int origin, int bound) Validate the range between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).(package private) static void
validateRange
(long origin, long bound) Validate the range between the specifiedorigin
(inclusive) and the specifiedbound
(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.
-
Field Details
-
INVALID_STREAM_SIZE
Message for an invalid stream size.- See Also:
-
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
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
- ifsize
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
- ifbound
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
- ifbound
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
- ifbound
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
- ifbound
is 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
- iforigin
is 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
- iforigin
is 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
- iforigin
is not finite, orbound
is not finite, ororigin
is 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.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 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 < 0
as 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
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
Generates anint
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) andn
(exclusive).
-
nextInt
Generates anint
value 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
int
value betweenorigin
(inclusive) andbound
(exclusive).
-
nextLong
Generates anlong
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) andn
(exclusive).
-
nextLong
Generates along
value 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
long
value betweenorigin
(inclusive) andbound
(exclusive).
-
nextFloat
Generates afloat
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) andbound
(exclusive).
-
nextFloat
Generates afloat
value 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 aboveorigin
and finite.- Returns:
- a random
float
value betweenorigin
(inclusive) andbound
(exclusive).
-
nextDouble
Generates adouble
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) andbound
(exclusive).
-
nextDouble
Generates adouble
value 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 aboveorigin
and finite.- Returns:
- a random
double
value betweenorigin
(inclusive) andbound
(exclusive).
-