Package org.apache.commons.rng.simple
Class JDKRandomBridge
java.lang.Object
java.util.Random
org.apache.commons.rng.simple.JDKRandomBridge
- All Implemented Interfaces:
Serializable
Subclass of
Random
that delegates
to a
RestorableUniformRandomProvider
instance but will otherwise rely
on the base class for generating all the random types.
Legacy applications coded against the JDK's API could use this subclass
of Random
in order to replace its linear congruential generator
by any RandomSource
.
Caveat: Use of this class is not recommended for new applications. In particular, there is no guarantee that the serialized form of this class will be compatible across (even minor) releases of the library.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate RestorableUniformRandomProvider
Delegate.private final boolean
Workaround JDK's "Random" bug: https://bugs.openjdk.java.net/browse/JDK-8154225.private static final long
Serializable version identifier.private final RandomSource
Source. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected int
next
(int n) Delegates the generation of 32 random bits to theRandomSource
argument provided atconstruction
.private void
readObject
(ObjectInputStream input) Deserialization method.void
setSeed
(long seed) private void
writeObject
(ObjectOutputStream output) Serialization method.
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerializable version identifier.- See Also:
-
source
Source. -
delegate
Delegate. -
isInitialized
private final transient boolean isInitializedWorkaround JDK's "Random" bug: https://bugs.openjdk.java.net/browse/JDK-8154225.
-
-
Constructor Details
-
JDKRandomBridge
Creates a new instance.- Parameters:
source
- Source of randomness.seed
- Seed. Can benull
.
-
-
Method Details
-
setSeed
public void setSeed(long seed) -
next
protected int next(int n) Delegates the generation of 32 random bits to theRandomSource
argument provided atconstruction
. The returned value is such that if the source of randomness isRandomSource.JDK
, all the generated values will be identical to those produced by the same sequence of calls on aRandom
instance initialized with the same seed. -
writeObject
Serialization method.- Parameters:
output
- Output stream.- Throws:
IOException
- if an error occurs.
-
readObject
Deserialization method.- Parameters:
input
- Input stream.- Throws:
IOException
- if an error occurs.ClassNotFoundException
- if an error occurs.
-