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
A provider that uses the
Random.nextInt() method of the JDK's
Random 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 ClassesModifier and TypeClassDescriptionprivate static final classAnObjectInputStreamthat's restricted to deserialize onlyRandomusing look-ahead deserialization. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected byte[]Creates a snapshot of the RNG state.intnext()Return the next random value.protected voidsetStateInternal(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, resetCachedStateMethods inherited from class org.apache.commons.rng.core.BaseProvider
checkIndex, checkStateSize, composeStateInternal, extendSeed, extendSeed, fillState, fillState, restoreState, saveState, splitStateInternal, toString
-
Field Details
-
delegate
Delegate. Cannot be "final" (to allow serialization).
-
-
Constructor Details
-
JDKRandom
Creates an instance with the given seed.- Parameters:
seed- Initial seed.
-
-
Method Details
-
next
public int next()Return the next random value.- Returns:
- the next random value.
- See Also:
-
getStateInternal
protected byte[] getStateInternal()Creates a snapshot of the RNG state.- Overrides:
getStateInternalin classIntProvider- Returns:
- the internal state.
-
setStateInternal
protected void setStateInternal(byte[] s) Resets the RNG to the givenstate.- Overrides:
setStateInternalin classIntProvider- Parameters:
s- State (previously obtained by a call toBaseProvider.getStateInternal()).- See Also:
-