Class SingleThreadSplittableRandomAdapter
- 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.SingleThreadSplittableRandomAdapter
-
- All Implemented Interfaces:
ByteArrayReseedableRandom
,EntropyCountingRandom
,RepeatableRandom
,Dumpable
,Serializable
public class SingleThreadSplittableRandomAdapter extends BaseSplittableRandomAdapter
Simple, non-thread-safe implementation ofBaseRandom
that wraps aSplittableRandom
.- Author:
- Chris Hennick
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected 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 Constructor Description SingleThreadSplittableRandomAdapter()
Use theDefaultSeedGenerator
to create the seed for theSplittableRandom
.SingleThreadSplittableRandomAdapter(byte[] seed)
Use the provided seed for theSplittableRandom
.SingleThreadSplittableRandomAdapter(long seed)
Use the provided seed for theSplittableRandom
.SingleThreadSplittableRandomAdapter(SeedGenerator seedGenerator)
Use the provided seed generation strategy to create the seed for theSplittableRandom
.
-
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.protected void
debitEntropy(long bits)
Must be redeclared in this package so thatSplittableRandomAdapter
can access it.protected SplittableRandom
getSplittableRandom()
Returns this SingleThreadSplittableRandomAdapter's onlySplittableRandom
.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, 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, checkValidRange, creditEntropyForNewSeed, doubles, doubles, doubles, doubles, dump, entropyOfInt, entropyOfLong, fallbackSetSeedIfInitialized, gaussians, gaussians, getEntropyBits, getRandomSeeder, getSeed, initTransientFields, internalNextGaussian, ints, ints, ints, ints, longs, longs, longs, longs, nextDouble, nextElement, nextElement, nextEnum, nextLong, setRandomSeeder, setSeed, supportsMultipleSeedLengths, usesParallelStreams, withProbability
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.github.pr0methean.betterrandom.EntropyCountingRandom
needsReseedingEarly
-
-
-
-
Field Detail
-
delegate
protected transient volatile 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
-
SingleThreadSplittableRandomAdapter
public SingleThreadSplittableRandomAdapter(SeedGenerator seedGenerator) throws SeedException
Use the provided seed generation strategy to create the seed for theSplittableRandom
.- Parameters:
seedGenerator
- The seed generation strategy that will provide the seed value for this RNG.- Throws:
SeedException
- if there is a problem generating a seed.
-
SingleThreadSplittableRandomAdapter
public SingleThreadSplittableRandomAdapter() throws SeedException
Use theDefaultSeedGenerator
to create the seed for theSplittableRandom
.- Throws:
SeedException
- if theDefaultSeedGenerator
fails to generate a seed.
-
SingleThreadSplittableRandomAdapter
public SingleThreadSplittableRandomAdapter(byte[] seed)
Use the provided seed for theSplittableRandom
.- Parameters:
seed
- The seed. Must be 8 bytes.
-
SingleThreadSplittableRandomAdapter
public SingleThreadSplittableRandomAdapter(long seed)
Use the provided seed for theSplittableRandom
.- Parameters:
seed
- The seed.
-
-
Method Detail
-
debitEntropy
protected void debitEntropy(long bits)
Must be redeclared in this package so thatSplittableRandomAdapter
can access it.- Overrides:
debitEntropy
in classBaseRandom
- Parameters:
bits
- The number of bits of entropy spent.
-
getSplittableRandom
protected SplittableRandom getSplittableRandom()
Returns this SingleThreadSplittableRandomAdapter's onlySplittableRandom
.- Specified by:
getSplittableRandom
in classBaseSplittableRandomAdapter
- Returns:
- the SplittableRandom
-
setSeed
public void setSeed(long seed)
Replaces the delegate with a newSplittableRandom
that uses the given seed.- Overrides:
setSeed
in classBaseRandom
- Parameters:
seed
- the new seed- See Also:
ByteArrayReseedableRandom.preferSeedWithLong()
-
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
-
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.
-
-