Class ReseedingThreadLocalRandomWrapper
- java.lang.Object
-
- java.util.Random
-
- io.github.pr0methean.betterrandom.prng.BaseRandom
-
- io.github.pr0methean.betterrandom.prng.adapter.RandomWrapper
-
- io.github.pr0methean.betterrandom.prng.adapter.ThreadLocalRandomWrapper
-
- io.github.pr0methean.betterrandom.prng.adapter.ReseedingThreadLocalRandomWrapper
-
- All Implemented Interfaces:
ByteArrayReseedableRandom,EntropyCountingRandom,Java8CompatRandom,RepeatableRandom,Dumpable,Serializable
public class ReseedingThreadLocalRandomWrapper extends ThreadLocalRandomWrapper
AThreadLocalRandomWrapperthat reseeds all its instances using aSimpleRandomSeeder.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class io.github.pr0methean.betterrandom.prng.adapter.ThreadLocalRandomWrapper
threadLocal
-
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 ReseedingThreadLocalRandomWrapper(int seedSize, SeedGenerator seedGenerator, java8.util.function.Function<byte[],? extends BaseRandom> creator)Wraps a seed generator and a function that takes a seed byte array as input.ReseedingThreadLocalRandomWrapper(int seedSize, SimpleRandomSeeder randomSeederThread, java8.util.function.Function<byte[],? extends BaseRandom> creator, SeedGenerator seedGenerator)Wraps a seed generator and a function that takes a seed byte array as input.ReseedingThreadLocalRandomWrapper(SeedGenerator seedGenerator, java8.util.function.Supplier<? extends BaseRandom> initializer)Wraps the givenSupplier.ReseedingThreadLocalRandomWrapper(java8.util.function.Supplier<? extends BaseRandom> initializer, SimpleRandomSeeder randomSeederThread)Wraps the givenSupplier.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description SimpleRandomSeedergetRandomSeeder()Returns the current seed generator for this PRNG.voidsetRandomSeeder(SimpleRandomSeeder randomSeeder)Not supported, because this class uses a thread-local seed.static ReseedingThreadLocalRandomWrapperwrapLegacy(java8.util.function.LongFunction<Random> legacyCreator, SeedGenerator seedGenerator)Uses this class andRandomWrapperto decorate any implementation ofRandomthat can be constructed from alongseed into a fully-concurrent one.-
Methods inherited from class io.github.pr0methean.betterrandom.prng.adapter.ThreadLocalRandomWrapper
addSubclassFields, debitEntropy, getEntropyBits, getNewSeedLength, getSeed, getWrapped, nextBoolean, nextBytes, nextDouble, nextDoubleNoEntropyDebit, nextFloat, nextGaussian, nextInt, nextInt, nextInt, nextLong, nextLong, nextLong, nextLongNoEntropyDebit, preferSeedWithLong, setSeed, setSeedInternal, withProbability, withProbabilityInternal, wrapLongCreatorAsByteArrayCreator
-
Methods inherited from class io.github.pr0methean.betterrandom.prng.adapter.RandomWrapper
next, setWrapped, supportsMultipleSeedLengths, toString, usesParallelStreams
-
Methods inherited from class io.github.pr0methean.betterrandom.prng.BaseRandom
checkLength, creditEntropyForNewSeed, doubles, doubles, doubles, doubles, dump, entropyOfInt, entropyOfLong, fallbackSetSeedIfInitialized, gaussians, gaussians, initTransientFields, internalNextGaussian, ints, ints, ints, ints, lockForNextGaussian, longs, longs, longs, longs, needsReseedingEarly, nextDouble, nextDouble, nextElement, nextElement, nextEnum, setSeed, unlockForNextGaussian
-
-
-
-
Constructor Detail
-
ReseedingThreadLocalRandomWrapper
public ReseedingThreadLocalRandomWrapper(SeedGenerator seedGenerator, java8.util.function.Supplier<? extends BaseRandom> initializer)
Wraps the givenSupplier. Uses the givenSimpleRandomSeederto reseed PRNGs, but not to initialize them unless theSupplierdoes so. This ThreadLocalRandomWrapper will be serializable if theSupplieris serializable.- Parameters:
initializer- a supplier that will be called to provide the initialBaseRandomfor each thread.seedGenerator- The seed generation strategy whoseSimpleRandomSeederwill be used to reseed each thread's PRNG.
-
ReseedingThreadLocalRandomWrapper
public ReseedingThreadLocalRandomWrapper(java8.util.function.Supplier<? extends BaseRandom> initializer, SimpleRandomSeeder randomSeederThread)
Wraps the givenSupplier. Uses the givenSimpleRandomSeederto reseed PRNGs, but not to initialize them unless theSupplierdoes so. This ThreadLocalRandomWrapper will be serializable if theSupplieris serializable.- Parameters:
initializer- a supplier that will be called to provide the initialBaseRandomfor each threadrandomSeederThread- a random seeder that will reseed the PRNG for each thread when necessary
-
ReseedingThreadLocalRandomWrapper
public ReseedingThreadLocalRandomWrapper(int seedSize, SeedGenerator seedGenerator, java8.util.function.Function<byte[],? extends BaseRandom> creator) throws SeedExceptionWraps a seed generator and a function that takes a seed byte array as input. This ReseedingThreadLocalRandomWrapper will be serializable if theFunctionis serializable.- Parameters:
seedSize- the size of seed arrays to generate.seedGenerator- The seed generation strategy that will provide the seed value for each thread'sBaseRandom, both at initialization and through the correspondingSimpleRandomSeeder.creator- aFunctionthat creates aBaseRandomfrom each seed. Probably a constructor reference.- Throws:
SeedException- ifseedGeneratorfails to generate an initial seed
-
ReseedingThreadLocalRandomWrapper
public ReseedingThreadLocalRandomWrapper(int seedSize, SimpleRandomSeeder randomSeederThread, java8.util.function.Function<byte[],? extends BaseRandom> creator, SeedGenerator seedGenerator) throws SeedExceptionWraps a seed generator and a function that takes a seed byte array as input. This ReseedingThreadLocalRandomWrapper will be serializable if theFunctionis serializable.- Parameters:
seedSize- the size of seed arrays to generate.randomSeederThread- The random seeder to use for reseeding.creator- aFunctionthat creates aBaseRandomfrom each seed.seedGenerator- the seed generator for initialization.- Throws:
SeedException- ifseedGeneratorfails to generate an initial seed
-
-
Method Detail
-
wrapLegacy
public static ReseedingThreadLocalRandomWrapper wrapLegacy(java8.util.function.LongFunction<Random> legacyCreator, SeedGenerator seedGenerator)
Uses this class andRandomWrapperto decorate any implementation ofRandomthat can be constructed from alongseed into a fully-concurrent one.- Parameters:
legacyCreator- a function that provides theRandomthat underlies the returned wrapper on each thread, taking a seed as input.seedGenerator- the seed generator whose output will be fed tolegacyCreator.- Returns:
- a ThreadLocalRandomWrapper decorating instances created by
legacyCreator.
-
setRandomSeeder
public void setRandomSeeder(SimpleRandomSeeder randomSeeder)
Description copied from class:ThreadLocalRandomWrapperNot supported, because this class uses a thread-local seed.- Overrides:
setRandomSeederin classThreadLocalRandomWrapper- Parameters:
randomSeeder- ignored.
-
getRandomSeeder
public SimpleRandomSeeder getRandomSeeder()
Description copied from class:BaseRandomReturns the current seed generator for this PRNG.- Overrides:
getRandomSeederin classThreadLocalRandomWrapper- Returns:
- the current seed generator, or null if there is none
-
-