Package org.apache.commons.rng
Interface UniformRandomProvider
-
- All Known Subinterfaces:
JumpableUniformRandomProvider
,LongJumpableUniformRandomProvider
,RestorableUniformRandomProvider
,SplittableUniformRandomProvider
public interface UniformRandomProvider
Applies to generators of random number sequences that follow a uniform distribution.- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default DoubleStream
doubles()
Returns an effectively unlimited stream ofdouble
values between 0 (inclusive) and 1 (exclusive).default DoubleStream
doubles(double origin, double bound)
Returns an effectively unlimited stream ofdouble
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).default DoubleStream
doubles(long streamSize)
Returns a stream producing the givenstreamSize
number ofdouble
values between 0 (inclusive) and 1 (exclusive).default DoubleStream
doubles(long streamSize, double origin, double bound)
Returns a stream producing the givenstreamSize
number ofdouble
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).default IntStream
ints()
Returns an effectively unlimited stream ofint
values.default IntStream
ints(int origin, int bound)
Returns an effectively unlimited stream ofint
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).default IntStream
ints(long streamSize)
Returns a stream producing the givenstreamSize
number ofint
values.default IntStream
ints(long streamSize, int origin, int bound)
Returns a stream producing the givenstreamSize
number ofint
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).default LongStream
longs()
Returns an effectively unlimited stream oflong
values.default LongStream
longs(long streamSize)
Returns a stream producing the givenstreamSize
number oflong
values.default LongStream
longs(long origin, long bound)
Returns an effectively unlimited stream oflong
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).default LongStream
longs(long streamSize, long origin, long bound)
Returns a stream producing the givenstreamSize
number oflong
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).default boolean
nextBoolean()
Generates aboolean
value.default void
nextBytes(byte[] bytes)
Generatesbyte
values and places them into a user-supplied array.default void
nextBytes(byte[] bytes, int start, int len)
Generatesbyte
values and places them into a user-supplied array.default double
nextDouble()
Generates adouble
value between 0 (inclusive) and 1 (exclusive).default double
nextDouble(double bound)
Generates adouble
value between 0 (inclusive) and the specifiedbound
(exclusive).default double
nextDouble(double origin, double bound)
Generates adouble
value between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).default float
nextFloat()
Generates afloat
value between 0 (inclusive) and 1 (exclusive).default float
nextFloat(float bound)
Generates afloat
value between 0 (inclusive) and the specifiedbound
(exclusive).default float
nextFloat(float origin, float bound)
Generates afloat
value between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).default int
nextInt()
Generates anint
value.default int
nextInt(int n)
Generates anint
value between 0 (inclusive) and the specified value (exclusive).default int
nextInt(int origin, int bound)
Generates anint
value between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).long
nextLong()
Generates along
value.default long
nextLong(long n)
Generates along
value between 0 (inclusive) and the specified value (exclusive).default long
nextLong(long origin, long bound)
Generates along
value between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).
-
-
-
Method Detail
-
nextBytes
default void nextBytes(byte[] bytes)
Generatesbyte
values and places them into a user-supplied array.The number of random bytes produced is equal to the length of the byte array.
- Parameters:
bytes
- Byte array in which to put the random bytes. Cannot benull
.
-
nextBytes
default void nextBytes(byte[] bytes, int start, int len)
Generatesbyte
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.
- Parameters:
bytes
- Array in which to put the generated bytes. Cannot benull
.start
- Index at which to start inserting the generated bytes.len
- Number of bytes to insert.- Throws:
IndexOutOfBoundsException
- ifstart < 0
orstart >= bytes.length
.IndexOutOfBoundsException
- iflen < 0
orlen > bytes.length - start
.
-
nextInt
default int nextInt()
Generates anint
value.- Returns:
- the next random value.
-
nextInt
default int nextInt(int n)
Generates anint
value between 0 (inclusive) and the specified value (exclusive).- Parameters:
n
- Bound on the random number to be returned. Must be positive.- Returns:
- a random
int
value between 0 (inclusive) andn
(exclusive). - Throws:
IllegalArgumentException
- ifn
is not above zero.
-
nextInt
default int nextInt(int origin, int bound)
Generates anint
value 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.- Returns:
- a random
int
value betweenorigin
(inclusive) andbound
(exclusive). - Throws:
IllegalArgumentException
- iforigin
is greater than or equal tobound
.- Since:
- 1.5
-
nextLong
long nextLong()
Generates along
value.- Returns:
- the next random value.
-
nextLong
default long nextLong(long n)
Generates along
value between 0 (inclusive) and the specified value (exclusive).- Parameters:
n
- Bound on the random number to be returned. Must be positive.- Returns:
- a random
long
value between 0 (inclusive) andn
(exclusive). - Throws:
IllegalArgumentException
- ifn
is not greater than 0.
-
nextLong
default long nextLong(long origin, long bound)
Generates along
value 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.- Returns:
- a random
long
value betweenorigin
(inclusive) andbound
(exclusive). - Throws:
IllegalArgumentException
- iforigin
is greater than or equal tobound
.- Since:
- 1.5
-
nextBoolean
default boolean nextBoolean()
Generates aboolean
value.- Returns:
- the next random value.
-
nextFloat
default float nextFloat()
Generates afloat
value between 0 (inclusive) and 1 (exclusive).- Returns:
- the next random value between 0 (inclusive) and 1 (exclusive).
-
nextFloat
default float nextFloat(float bound)
Generates afloat
value between 0 (inclusive) and the specifiedbound
(exclusive).- Parameters:
bound
- Upper bound (exclusive) on the random number to be returned.- Returns:
- a random
float
value between 0 (inclusive) andbound
(exclusive). - Throws:
IllegalArgumentException
- ifbound
is not both finite and greater than 0.- Since:
- 1.5
-
nextFloat
default float nextFloat(float origin, float bound)
Generates afloat
value 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.- Returns:
- a random
float
value betweenorigin
(inclusive) andbound
(exclusive). - Throws:
IllegalArgumentException
- iforigin
is not finite, orbound
is not finite, ororigin
is greater than or equal tobound
.- Since:
- 1.5
-
nextDouble
default double nextDouble()
Generates adouble
value between 0 (inclusive) and 1 (exclusive).- Returns:
- the next random value between 0 (inclusive) and 1 (exclusive).
-
nextDouble
default double nextDouble(double bound)
Generates adouble
value between 0 (inclusive) and the specifiedbound
(exclusive).- Parameters:
bound
- Upper bound (exclusive) on the random number to be returned.- Returns:
- a random
double
value between 0 (inclusive) andbound
(exclusive). - Throws:
IllegalArgumentException
- ifbound
is not both finite and greater than 0.- Since:
- 1.5
-
nextDouble
default double nextDouble(double origin, double bound)
Generates adouble
value 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.- Returns:
- a random
double
value betweenorigin
(inclusive) andbound
(exclusive). - Throws:
IllegalArgumentException
- iforigin
is not finite, orbound
is not finite, ororigin
is greater than or equal tobound
.- Since:
- 1.5
-
ints
default IntStream ints()
Returns an effectively unlimited stream ofint
values.- Returns:
- a stream of random
int
values. - Since:
- 1.5
-
ints
default IntStream ints(int origin, int bound)
Returns an effectively unlimited stream ofint
values 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.- Returns:
- a stream of random values between the specified
origin
(inclusive) and the specifiedbound
(exclusive). - Throws:
IllegalArgumentException
- iforigin
is greater than or equal tobound
.- Since:
- 1.5
-
ints
default IntStream ints(long streamSize)
Returns a stream producing the givenstreamSize
number ofint
values.- Parameters:
streamSize
- Number of values to generate.- Returns:
- a stream of random
int
values; the stream is limited to the givenstreamSize
. - Throws:
IllegalArgumentException
- ifstreamSize
is negative.- Since:
- 1.5
-
ints
default IntStream ints(long streamSize, int origin, int bound)
Returns a stream producing the givenstreamSize
number ofint
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).- Parameters:
streamSize
- Number of values to generate.origin
- Lower bound on the random number to be returned.bound
- Upper bound (exclusive) on the random number to be returned.- Returns:
- a stream of random values between the specified
origin
(inclusive) and the specifiedbound
(exclusive); the stream is limited to the givenstreamSize
. - Throws:
IllegalArgumentException
- ifstreamSize
is negative, or iforigin
is greater than or equal tobound
.- Since:
- 1.5
-
longs
default LongStream longs()
Returns an effectively unlimited stream oflong
values.- Returns:
- a stream of random
long
values. - Since:
- 1.5
-
longs
default LongStream longs(long origin, long bound)
Returns an effectively unlimited stream oflong
values 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.- Returns:
- a stream of random values between the specified
origin
(inclusive) and the specifiedbound
(exclusive). - Throws:
IllegalArgumentException
- iforigin
is greater than or equal tobound
.- Since:
- 1.5
-
longs
default LongStream longs(long streamSize)
Returns a stream producing the givenstreamSize
number oflong
values.- Parameters:
streamSize
- Number of values to generate.- Returns:
- a stream of random
long
values; the stream is limited to the givenstreamSize
. - Throws:
IllegalArgumentException
- ifstreamSize
is negative.- Since:
- 1.5
-
longs
default LongStream longs(long streamSize, long origin, long bound)
Returns a stream producing the givenstreamSize
number oflong
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).- Parameters:
streamSize
- Number of values to generate.origin
- Lower bound on the random number to be returned.bound
- Upper bound (exclusive) on the random number to be returned.- Returns:
- a stream of random values between the specified
origin
(inclusive) and the specifiedbound
(exclusive); the stream is limited to the givenstreamSize
. - Throws:
IllegalArgumentException
- ifstreamSize
is negative, or iforigin
is greater than or equal tobound
.- Since:
- 1.5
-
doubles
default DoubleStream doubles()
Returns an effectively unlimited stream ofdouble
values between 0 (inclusive) and 1 (exclusive).- Returns:
- a stream of random values between 0 (inclusive) and 1 (exclusive).
- Since:
- 1.5
-
doubles
default DoubleStream doubles(double origin, double bound)
Returns an effectively unlimited stream ofdouble
values 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.- Returns:
- a stream of random values between the specified
origin
(inclusive) and the specifiedbound
(exclusive). - Throws:
IllegalArgumentException
- iforigin
is not finite, orbound
is not finite, ororigin
is greater than or equal tobound
.- Since:
- 1.5
-
doubles
default DoubleStream doubles(long streamSize)
Returns a stream producing the givenstreamSize
number ofdouble
values between 0 (inclusive) and 1 (exclusive).- Parameters:
streamSize
- Number of values to generate.- Returns:
- a stream of random values between 0 (inclusive) and 1 (exclusive);
the stream is limited to the given
streamSize
. - Throws:
IllegalArgumentException
- ifstreamSize
is negative.- Since:
- 1.5
-
doubles
default DoubleStream doubles(long streamSize, double origin, double bound)
Returns a stream producing the givenstreamSize
number ofdouble
values between the specifiedorigin
(inclusive) and the specifiedbound
(exclusive).- Parameters:
streamSize
- Number of values to generate.origin
- Lower bound on the random number to be returned.bound
- Upper bound (exclusive) on the random number to be returned.- Returns:
- a stream of random values between the specified
origin
(inclusive) and the specifiedbound
(exclusive); the stream is limited to the givenstreamSize
. - Throws:
IllegalArgumentException
- ifstreamSize
is negative, or iforigin
is not finite, orbound
is not finite, ororigin
is greater than or equal tobound
.- Since:
- 1.5
-
-