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 ofBaseRandomthat wraps aSplittableRandom.- Author:
- Chris Hennick
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected SplittableRandomdelegateThe masterSplittableRandomthat will either be delegated to directly (seeSingleThreadSplittableRandomAdapteror 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 theDefaultSeedGeneratorto 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.ToStringHelperaddSubclassFields(MoreObjects.ToStringHelper original)Adds the fields that were not inherited from BaseRandom to the givenMoreObjects.ToStringHelperfor dumping.protected voiddebitEntropy(long bits)Must be redeclared in this package so thatSplittableRandomAdaptercan access it.protected SplittableRandomgetSplittableRandom()Returns this SingleThreadSplittableRandomAdapter's onlySplittableRandom.voidsetSeed(long seed)Replaces the delegate with a newSplittableRandomthat uses the given seed.protected voidsetSeedInternal(byte[] seed)Replaces the delegate with a newSplittableRandomthat 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 masterSplittableRandomthat will either be delegated to directly (seeSingleThreadSplittableRandomAdapteror 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 SeedExceptionUse theDefaultSeedGeneratorto create the seed for theSplittableRandom.- Throws:
SeedException- if theDefaultSeedGeneratorfails 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 thatSplittableRandomAdaptercan access it.- Overrides:
debitEntropyin classBaseRandom- Parameters:
bits- The number of bits of entropy spent.
-
getSplittableRandom
protected SplittableRandom getSplittableRandom()
Returns this SingleThreadSplittableRandomAdapter's onlySplittableRandom.- Specified by:
getSplittableRandomin classBaseSplittableRandomAdapter- Returns:
- the SplittableRandom
-
setSeed
public void setSeed(long seed)
Replaces the delegate with a newSplittableRandomthat uses the given seed.- Overrides:
setSeedin classBaseRandom- Parameters:
seed- the new seed- See Also:
ByteArrayReseedableRandom.preferSeedWithLong()
-
setSeedInternal
protected void setSeedInternal(byte[] seed)
Replaces the delegate with a newSplittableRandomthat uses the given seed.- Overrides:
setSeedInternalin classBaseRandom- Parameters:
seed- the new seed; must be 8 bytes
-
addSubclassFields
protected MoreObjects.ToStringHelper addSubclassFields(MoreObjects.ToStringHelper original)
Description copied from class:BaseRandomAdds the fields that were not inherited from BaseRandom to the givenMoreObjects.ToStringHelperfor dumping.- Specified by:
addSubclassFieldsin classBaseRandom- Parameters:
original- aMoreObjects.ToStringHelperobject.- Returns:
originalwith the fields not inherited from BaseRandom written to it.
-
-