Class JDKRandom
- java.lang.Object
-
- org.apache.commons.rng.core.BaseProvider
-
- org.apache.commons.rng.core.source32.IntProvider
-
- org.apache.commons.rng.core.source32.JDKRandom
-
- All Implemented Interfaces:
RandomIntSource
,RestorableUniformRandomProvider
,UniformRandomProvider
public class JDKRandom extends IntProvider
A provider that uses theRandom.nextInt()
method of the JDK'sRandom
class as the source of randomness.Caveat: All the other calls will be redirected to the methods implemented within this library.
The state of this source of randomness is saved and restored through the serialization of the
Random
instance.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
JDKRandom.ValidatingObjectInputStream
AnObjectInputStream
that's restricted to deserialize onlyRandom
using look-ahead deserialization.
-
Field Summary
Fields Modifier and Type Field Description private java.util.Random
delegate
Delegate.
-
Constructor Summary
Constructors Constructor Description JDKRandom(java.lang.Long seed)
Creates an instance with the given seed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
getStateInternal()
Creates a snapshot of the RNG state.int
next()
Return the next random value.protected void
setStateInternal(byte[] s)
Resets the RNG to the givenstate
.-
Methods inherited from class org.apache.commons.rng.core.source32.IntProvider
nextBoolean, nextBytes, nextBytes, nextBytesFill, nextDouble, nextInt, nextLong, resetCachedState
-
Methods inherited from class org.apache.commons.rng.core.BaseProvider
checkIndex, checkStateSize, composeStateInternal, extendSeed, extendSeed, fillState, fillState, restoreState, saveState, splitStateInternal, toString
-
-
-
-
Method Detail
-
next
public int next()
Return the next random value.- Returns:
- the next random value.
- See Also:
Random.nextInt()
-
getStateInternal
protected byte[] getStateInternal()
Creates a snapshot of the RNG state.- Overrides:
getStateInternal
in classIntProvider
- Returns:
- the internal state.
-
setStateInternal
protected void setStateInternal(byte[] s)
Resets the RNG to the givenstate
.- Overrides:
setStateInternal
in classIntProvider
- Parameters:
s
- State (previously obtained by a call toBaseProvider.getStateInternal()
).- See Also:
BaseProvider.checkStateSize(byte[],int)
-
-