Class EntropyBlockingSplittableRandomAdapter
- 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.SplittableRandomAdapter
- 
- io.github.pr0methean.betterrandom.prng.adapter.EntropyBlockingSplittableRandomAdapter
 
 
 
 
 
- 
- All Implemented Interfaces:
- ByteArrayReseedableRandom,- EntropyCountingRandom,- Java8CompatRandom,- RepeatableRandom,- Dumpable,- Serializable
 
 public class EntropyBlockingSplittableRandomAdapter extends SplittableRandomAdapter ASplittableRandomAdapterthat blocks waiting to be reseeded if its entropy drops too low. Reseeding is done on aSimpleRandomSeederif provided, and on the calling thread otherwise. Entropy count is thread-local, so consuming entropy on one thread won't directly cause blocking on another thread.- See Also:
- Serialized Form
 
- 
- 
Field Summary- 
Fields inherited from class io.github.pr0methean.betterrandom.prng.adapter.SplittableRandomAdapterthreadLocal
 - 
Fields inherited from class io.github.pr0methean.betterrandom.prng.BaseRandomENTROPY_OF_DOUBLE, ENTROPY_OF_FLOAT, entropyBits, lock, randomSeeder, seed, superConstructorFinished
 
- 
 - 
Constructor SummaryConstructors Constructor Description EntropyBlockingSplittableRandomAdapter(SeedGenerator seedGenerator, SimpleRandomSeeder randomSeeder, long minimumEntropy)Creates an instance.EntropyBlockingSplittableRandomAdapter(SimpleRandomSeeder randomSeeder, long minimumEntropy)Creates an instance.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description protected BaseRandomcreateDelegate()Creates the delegate for the calling thread.protected voiddebitEntropy(long bits)Record that entropy has been spent, and schedule a reseeding if this PRNG has now spent as much as it's been seeded with.byte[]getSeed()Returns the calling thread's seed, not the master seed.protected java8.util.SplittableRandomgetSplittableRandom()Returns theSplittableRandomthat is to be used to generate random numbers for the current thread.voidsetSeed(byte[] seed)Reseed this PRNG.voidsetSeed(long seed)Sets the seed of this random number generator using a single long seed, if this implementation supports that.- 
Methods inherited from class io.github.pr0methean.betterrandom.prng.adapter.SplittableRandomAdapteraddSubclassFields, equals, getEntropyBits, hashCode, nextGaussian, setRandomSeeder, setSeedInternal, toString, usesParallelStreams
 - 
Methods inherited from class io.github.pr0methean.betterrandom.prng.adapter.BaseSplittableRandomAdaptergetNewSeedLength, lockForNextGaussian, next, nextBoolean, nextBytes, nextDouble, nextDouble, nextDoubleNoEntropyDebit, nextFloat, nextInt, nextInt, nextInt, nextLong, nextLong, nextLongNoEntropyDebit, preferSeedWithLong, unlockForNextGaussian, withProbabilityInternal
 - 
Methods inherited from class io.github.pr0methean.betterrandom.prng.BaseRandomcheckLength, creditEntropyForNewSeed, doubles, doubles, doubles, doubles, dump, entropyOfInt, entropyOfLong, fallbackSetSeedIfInitialized, gaussians, gaussians, getRandomSeeder, initTransientFields, internalNextGaussian, ints, ints, ints, ints, longs, longs, longs, longs, needsReseedingEarly, nextDouble, nextElement, nextElement, nextEnum, nextLong, supportsMultipleSeedLengths, withProbability
 
- 
 
- 
- 
- 
Constructor Detail- 
EntropyBlockingSplittableRandomAdapterpublic EntropyBlockingSplittableRandomAdapter(SimpleRandomSeeder randomSeeder, long minimumEntropy) Creates an instance.- Parameters:
- randomSeeder- the- SimpleRandomSeederthat will reseed this. Its seed generator is also used on the calling thread to generate an initial seed when this- EntropyBlockingSplittableRandomAdapteris used the first time on each thread.
- minimumEntropy- the minimum entropy; operations that would drop the entropy below this amount will instead block until the calling thread's PRNG is reseeded. Should generally be zero or negative.
 
 - 
EntropyBlockingSplittableRandomAdapterpublic EntropyBlockingSplittableRandomAdapter(@Nullable SeedGenerator seedGenerator, SimpleRandomSeeder randomSeeder, long minimumEntropy) Creates an instance.- Parameters:
- seedGenerator- the seed generator that will generate an initial PRNG seed for each thread
- randomSeeder- the- SimpleRandomSeederthat will reseed this
- minimumEntropy- the minimum entropy; operations that would drop the entropy below this amount will instead block until the calling thread's PRNG is reseeded. Should generally be zero or negative.
 
 
- 
 - 
Method Detail- 
createDelegateprotected BaseRandom createDelegate() Description copied from class:SplittableRandomAdapterCreates the delegate for the calling thread.- Overrides:
- createDelegatein class- SplittableRandomAdapter
- Returns:
- the thread-local delegate
 
 - 
setSeedpublic void setSeed(byte[] seed) Reseed this PRNG.Most subclasses should override Applies only to the calling thread.BaseRandom.setSeedInternal(byte[])instead of this method, so that they will deserialize properly.- Specified by:
- setSeedin interface- ByteArrayReseedableRandom
- Overrides:
- setSeedin class- BaseRandom
- Parameters:
- seed- The PRNG's new seed.
 
 - 
setSeedpublic void setSeed(long seed) Sets the seed of this random number generator using a single long seed, if this implementation supports that. If it is capable of using 64 bits or less of seed data (i.e. if{@link #getNewSeedLength()} <= {@link Long#BYTES}), then this method shall replace the entire seed asRandom.setSeed(long)does; otherwise, it shall either combine the input with the existing seed asSecureRandom.setSeed(long)does, or it shall generate a new seed using theDefaultSeedGenerator. The latter is a backward-compatibility measure and can be very slow. Applies only to the calling thread.- Specified by:
- setSeedin interface- Java8CompatRandom
- Overrides:
- setSeedin class- BaseRandom
 
 - 
getSplittableRandomprotected java8.util.SplittableRandom getSplittableRandom() Description copied from class:BaseSplittableRandomAdapterReturns theSplittableRandomthat is to be used to generate random numbers for the current thread. (SplittableRandomisn't thread-safe.) Called by all thenext*methods.- Overrides:
- getSplittableRandomin class- SplittableRandomAdapter
- Returns:
- the SplittableRandomto use with the current thread.
 
 - 
getSeedpublic byte[] getSeed() Returns the calling thread's seed, not the master seed.- Specified by:
- getSeedin interface- RepeatableRandom
- Overrides:
- getSeedin class- SplittableRandomAdapter
- Returns:
- the seed for the calling thread
 
 - 
debitEntropyprotected void debitEntropy(long bits) Description copied from class:BaseRandomRecord that entropy has been spent, and schedule a reseeding if this PRNG has now spent as much as it's been seeded with.- Overrides:
- debitEntropyin class- SplittableRandomAdapter
- Parameters:
- bits- The number of bits of entropy spent.
 
 
- 
 
-