Package org.apache.commons.rng.simple
Class JDKRandomWrapper
- java.lang.Object
-
- org.apache.commons.rng.simple.JDKRandomWrapper
-
- All Implemented Interfaces:
UniformRandomProvider
public final class JDKRandomWrapper extends Object implements UniformRandomProvider
Wraps aRandominstance to implementUniformRandomProvider. All methods from theRandomthat match those inUniformRandomProviderare used directly.This class can be used to wrap an instance of
SecureRandom. TheSecureRandomclass provides cryptographic random number generation. The features available depend on the Java version and platform. Consult the Java documentation for more details.Note: Use of
java.util.Randomis not recommended for applications. There are many other pseudo-random number generators that are statistically superior and often faster (seeRandomSource).- Since:
- 1.3
- See Also:
SecureRandom,RandomSource
-
-
Constructor Summary
Constructors Constructor Description JDKRandomWrapper(Random rng)Create a wrapper around a Random instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleannextBoolean()Generates abooleanvalue.voidnextBytes(byte[] bytes)Generatesbytevalues and places them into a user-supplied array.voidnextBytes(byte[] bytes, int start, int len)Generatesbytevalues and places them into a user-supplied array.doublenextDouble()Generates adoublevalue between 0 (inclusive) and 1 (exclusive).floatnextFloat()Generates afloatvalue between 0 (inclusive) and 1 (exclusive).intnextInt()Generates anintvalue.intnextInt(int n)Generates anintvalue between 0 (inclusive) and the specified value (exclusive).longnextLong()Generates alongvalue.longnextLong(long n)Generates alongvalue between 0 (inclusive) and the specified value (exclusive).
-
-
-
Constructor Detail
-
JDKRandomWrapper
public JDKRandomWrapper(Random rng)
Create a wrapper around a Random instance.- Parameters:
rng- JDKRandominstance to which the random number generation is delegated.
-
-
Method Detail
-
nextBytes
public void nextBytes(byte[] bytes)
Generatesbytevalues and places them into a user-supplied array.The number of random bytes produced is equal to the length of the byte array.
- Specified by:
nextBytesin interfaceUniformRandomProvider- Parameters:
bytes- Byte array in which to put the random bytes. Cannot benull.
-
nextBytes
public void nextBytes(byte[] bytes, int start, int len)
Generatesbytevalues 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.
- Specified by:
nextBytesin interfaceUniformRandomProvider- 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.
-
nextInt
public int nextInt()
Generates anintvalue.- Specified by:
nextIntin interfaceUniformRandomProvider- Returns:
- the next random value.
-
nextInt
public int nextInt(int n)
Generates anintvalue between 0 (inclusive) and the specified value (exclusive).- Specified by:
nextIntin interfaceUniformRandomProvider- Parameters:
n- Bound on the random number to be returned. Must be positive.- Returns:
- a random
intvalue between 0 (inclusive) andn(exclusive).
-
nextLong
public long nextLong()
Generates alongvalue.- Specified by:
nextLongin interfaceUniformRandomProvider- Returns:
- the next random value.
-
nextLong
public long nextLong(long n)
Generates alongvalue between 0 (inclusive) and the specified value (exclusive).- Specified by:
nextLongin interfaceUniformRandomProvider- Parameters:
n- Bound on the random number to be returned. Must be positive.- Returns:
- a random
longvalue between 0 (inclusive) andn(exclusive).
-
nextBoolean
public boolean nextBoolean()
Generates abooleanvalue.- Specified by:
nextBooleanin interfaceUniformRandomProvider- Returns:
- the next random value.
-
nextFloat
public float nextFloat()
Generates afloatvalue between 0 (inclusive) and 1 (exclusive).- Specified by:
nextFloatin interfaceUniformRandomProvider- Returns:
- the next random value between 0 (inclusive) and 1 (exclusive).
-
nextDouble
public double nextDouble()
Generates adoublevalue between 0 (inclusive) and 1 (exclusive).- Specified by:
nextDoublein interfaceUniformRandomProvider- Returns:
- the next random value between 0 (inclusive) and 1 (exclusive).
-
-