Class DirectSplittableRandomAdapter
- java.lang.Object
-
- java.util.Random
-
- io.github.pr0methean.betterrandom.prng.BaseRandom
-
- io.github.pr0methean.betterrandom.prng.adapter.BaseSplittableRandomAdapter
-
- io.github.pr0methean.betterrandom.prng.adapter.DirectSplittableRandomAdapter
-
- All Implemented Interfaces:
ByteArrayReseedableRandom
,EntropyCountingRandom
,Java8CompatRandom
,RepeatableRandom
,Dumpable
,Serializable
- Direct Known Subclasses:
SingleThreadSplittableRandomAdapter
public abstract class DirectSplittableRandomAdapter extends BaseSplittableRandomAdapter
Abstract subclass ofBaseSplittableRandomAdapter
wheresetSeed(long)
andBaseRandom.setSeed(byte[])
replace theSplittableRandom
that's used in the context in which they are called. SeeSplittableRandomAdapter
for an example of when it does not make sense to extend this class.- Author:
- Chris Hennick
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java8.util.SplittableRandom
delegate
The masterSplittableRandom
that will either be delegated to directly (seeSingleThreadSplittableRandomAdapter
or be split usingSplittableRandom.split()
(seeSplittableRandomAdapter
) and have the splits delegated to.-
Fields inherited from class io.github.pr0methean.betterrandom.prng.BaseRandom
ENTROPY_OF_DOUBLE, ENTROPY_OF_FLOAT, entropyBits, lock, randomSeeder, seed, superConstructorFinished
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DirectSplittableRandomAdapter(byte[] seed)
Wraps aSplittableRandom
with the specified seed.protected
DirectSplittableRandomAdapter(long seed)
Wraps aSplittableRandom
with the specified seed.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MoreObjects.ToStringHelper
addSubclassFields(MoreObjects.ToStringHelper original)
Adds the fields that were not inherited from BaseRandom to the givenMoreObjects.ToStringHelper
for dumping.void
setSeed(long seed)
Replaces the delegate with a newSplittableRandom
that uses the given seed.protected void
setSeedInternal(byte[] seed)
Replaces the delegate with a newSplittableRandom
that uses the given seed.-
Methods inherited from class io.github.pr0methean.betterrandom.prng.adapter.BaseSplittableRandomAdapter
getNewSeedLength, getSplittableRandom, lockForNextGaussian, next, nextBoolean, nextBytes, nextDouble, nextDouble, nextDoubleNoEntropyDebit, nextFloat, nextGaussian, nextInt, nextInt, nextInt, nextLong, nextLong, nextLongNoEntropyDebit, preferSeedWithLong, unlockForNextGaussian, withProbabilityInternal
-
Methods inherited from class io.github.pr0methean.betterrandom.prng.BaseRandom
checkLength, creditEntropyForNewSeed, debitEntropy, doubles, doubles, doubles, doubles, dump, entropyOfInt, entropyOfLong, fallbackSetSeedIfInitialized, gaussians, gaussians, getEntropyBits, getRandomSeeder, getSeed, initTransientFields, internalNextGaussian, ints, ints, ints, ints, longs, longs, longs, longs, needsReseedingEarly, nextDouble, nextElement, nextElement, nextEnum, nextLong, setRandomSeeder, setSeed, supportsMultipleSeedLengths, usesParallelStreams, withProbability
-
-
-
-
Field Detail
-
delegate
protected transient volatile java8.util.SplittableRandom delegate
The masterSplittableRandom
that will either be delegated to directly (seeSingleThreadSplittableRandomAdapter
or be split usingSplittableRandom.split()
(seeSplittableRandomAdapter
) and have the splits delegated to.
-
-
Constructor Detail
-
DirectSplittableRandomAdapter
protected DirectSplittableRandomAdapter(byte[] seed)
Wraps aSplittableRandom
with the specified seed.- Parameters:
seed
- 8 bytes of seed data used to initialize the RNG.
-
DirectSplittableRandomAdapter
protected DirectSplittableRandomAdapter(long seed)
Wraps aSplittableRandom
with the specified seed.- Parameters:
seed
- the seed.
-
-
Method Detail
-
addSubclassFields
protected MoreObjects.ToStringHelper addSubclassFields(MoreObjects.ToStringHelper original)
Description copied from class:BaseRandom
Adds the fields that were not inherited from BaseRandom to the givenMoreObjects.ToStringHelper
for dumping.- Specified by:
addSubclassFields
in classBaseRandom
- Parameters:
original
- aMoreObjects.ToStringHelper
object.- Returns:
original
with the fields not inherited from BaseRandom written to it.
-
setSeedInternal
protected void setSeedInternal(byte[] seed)
Replaces the delegate with a newSplittableRandom
that uses the given seed.- Overrides:
setSeedInternal
in classBaseRandom
- Parameters:
seed
- the new seed; must be 8 bytes
-
setSeed
public void setSeed(long seed)
Replaces the delegate with a newSplittableRandom
that uses the given seed.- Specified by:
setSeed
in interfaceJava8CompatRandom
- Overrides:
setSeed
in classBaseRandom
- Parameters:
seed
- the new seed
-
-