Package org.apache.commons.rng
Interface UniformRandomProvider
-
- All Known Subinterfaces:
JumpableUniformRandomProvider
,LongJumpableUniformRandomProvider
,RestorableUniformRandomProvider
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 Modifier and Type Method Description boolean
nextBoolean()
Generates aboolean
value.void
nextBytes(byte[] bytes)
Generatesbyte
values and places them into a user-supplied array.void
nextBytes(byte[] bytes, int start, int len)
Generatesbyte
values and places them into a user-supplied array.double
nextDouble()
Generates adouble
value between 0 and 1.float
nextFloat()
Generates afloat
value between 0 and 1.int
nextInt()
Generates anint
value.int
nextInt(int n)
Generates anint
value between 0 (inclusive) and the specified value (exclusive).long
nextLong()
Generates along
value.long
nextLong(long n)
Generates along
value between 0 (inclusive) and the specified value (exclusive).
-
-
-
Method Detail
-
nextBytes
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 the byte array.
- Parameters:
bytes
- Byte array in which to put the random bytes. Cannot benull
.
-
nextBytes
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
int nextInt()
Generates anint
value.- Returns:
- the next random value.
-
nextInt
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 negative.
-
nextLong
long nextLong()
Generates along
value.- Returns:
- the next random value.
-
nextLong
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 negative.
-
nextBoolean
boolean nextBoolean()
Generates aboolean
value.- Returns:
- the next random value.
-
nextFloat
float nextFloat()
Generates afloat
value between 0 and 1.- Returns:
- the next random value between 0 and 1.
-
nextDouble
double nextDouble()
Generates adouble
value between 0 and 1.- Returns:
- the next random value between 0 and 1.
-
-