Package org.apache.commons.rng.simple
Class JDKRandomBridge
java.lang.Object
java.util.Random
org.apache.commons.rng.simple.JDKRandomBridge
- All Implemented Interfaces:
Serializable
,java.util.random.RandomGenerator
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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface java.util.random.RandomGenerator
java.util.random.RandomGenerator.ArbitrarilyJumpableGenerator, java.util.random.RandomGenerator.JumpableGenerator, java.util.random.RandomGenerator.LeapableGenerator, java.util.random.RandomGenerator.SplittableGenerator, java.util.random.RandomGenerator.StreamableGenerator
-
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) void
setSeed
(long seed) private void
writeObject
(ObjectOutputStream output) Methods inherited from class java.util.Random
doubles, doubles, doubles, doubles, from, ints, ints, ints, ints, longs, longs, longs, longs, nextBoolean, nextBytes, nextDouble, nextFloat, nextGaussian, nextInt, nextInt, nextLong
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.random.RandomGenerator
isDeprecated, nextDouble, nextDouble, nextExponential, nextFloat, nextFloat, nextGaussian, nextInt, nextLong, nextLong
-
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
- Parameters:
output
- Output stream.- Throws:
IOException
- if an error occurs.
-
readObject
- Parameters:
input
- Input stream.- Throws:
IOException
- if an error occurs.ClassNotFoundException
- if an error occurs.
-