Class LegacyRandomSeeder
- java.lang.Object
-
- io.github.pr0methean.betterrandom.util.Looper
-
- io.github.pr0methean.betterrandom.seed.SimpleRandomSeeder
-
- io.github.pr0methean.betterrandom.seed.LegacyRandomSeeder
-
- All Implemented Interfaces:
Serializable
public final class LegacyRandomSeeder extends SimpleRandomSeeder
ASimpleRandomSeeder
that can reseed any instance ofRandom
.- Author:
- Chris Hennick
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class io.github.pr0methean.betterrandom.seed.SimpleRandomSeeder
SimpleRandomSeeder.DefaultThreadFactory
-
-
Field Summary
-
Fields inherited from class io.github.pr0methean.betterrandom.seed.SimpleRandomSeeder
byteArrayPrngs, byteArrayPrngsThisIteration, DEFAULT_STOP_IF_EMPTY_FOR_NANOS, POLL_INTERVAL, seedGenerator, stopIfEmptyForNanos, waitForEntropyDrain, waitWhileEmpty
-
Fields inherited from class io.github.pr0methean.betterrandom.util.Looper
DEFAULT_THREAD_FACTORY, factory, lock, thread, threadLock
-
-
Constructor Summary
Constructors Constructor Description LegacyRandomSeeder(SeedGenerator seedGenerator)
Creates an instance using aSimpleRandomSeeder.DefaultThreadFactory
.LegacyRandomSeeder(SeedGenerator seedGenerator, ThreadFactory threadFactory)
Creates an instance whose thread will terminate if no PRNGs have been associated with it for 5 seconds.LegacyRandomSeeder(SeedGenerator seedGenerator, ThreadFactory threadFactory, long stopIfEmptyForNanos)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Random... randoms)
AddsRandom
instances.void
addLegacyRandoms(Collection<? extends Random> randoms)
AddsRandom
instances.protected void
clear()
Removes all PRNGs from this seeder.protected void
initTransientFields()
Initializes the transient instance fields for this class.boolean
isEmpty()
Returns true if noRandom
instances are registered with this LegacyRandomSeeder.protected boolean
iterate()
The task that will be iterated until it returns false.void
remove(Collection<? extends Random> randoms)
Removes PRNGs so that they will no longer be reseeded.String
toString()
-
Methods inherited from class io.github.pr0methean.betterrandom.seed.SimpleRandomSeeder
add, add, createSynchronizedWeakHashSet, equals, getSeedGenerator, hashCode, remove, reseedByteArrayReseedableRandoms, reseedWithLong, shutDown, stopIfEmpty, unregisterWithAll, wakeUp
-
-
-
-
Constructor Detail
-
LegacyRandomSeeder
public LegacyRandomSeeder(SeedGenerator seedGenerator, ThreadFactory threadFactory)
Creates an instance whose thread will terminate if no PRNGs have been associated with it for 5 seconds.- Parameters:
seedGenerator
- the seed generatorthreadFactory
- theThreadFactory
that will create this seeder's thread
-
LegacyRandomSeeder
public LegacyRandomSeeder(SeedGenerator seedGenerator, ThreadFactory threadFactory, long stopIfEmptyForNanos)
Creates an instance.- Parameters:
seedGenerator
- the seed generatorthreadFactory
- theThreadFactory
that will create this seeder's threadstopIfEmptyForNanos
- time in nanoseconds after which this thread will terminate if no PRNGs are attached
-
LegacyRandomSeeder
public LegacyRandomSeeder(SeedGenerator seedGenerator)
Creates an instance using aSimpleRandomSeeder.DefaultThreadFactory
.- Parameters:
seedGenerator
- the seed generator
-
-
Method Detail
-
initTransientFields
protected void initTransientFields()
Description copied from class:SimpleRandomSeeder
Initializes the transient instance fields for this class. Called by constructors and during deserialization.- Overrides:
initTransientFields
in classSimpleRandomSeeder
-
remove
public void remove(Collection<? extends Random> randoms)
Description copied from class:SimpleRandomSeeder
Removes PRNGs so that they will no longer be reseeded.- Overrides:
remove
in classSimpleRandomSeeder
- Parameters:
randoms
- the PRNGs to remove
-
add
public void add(Random... randoms)
AddsRandom
instances.- Parameters:
randoms
- the PRNGs to start reseeding
-
addLegacyRandoms
public void addLegacyRandoms(Collection<? extends Random> randoms)
AddsRandom
instances.- Parameters:
randoms
- the PRNGs to start reseeding
-
iterate
protected boolean iterate()
Description copied from class:Looper
The task that will be iterated until it returns false. Cannot be abstract for serialization reasons, but must be overridden in subclasses if they are instantiated without a targetRunnable
.- Overrides:
iterate
in classSimpleRandomSeeder
- Returns:
- true if this thread should iterate again.
-
isEmpty
public boolean isEmpty()
Description copied from class:SimpleRandomSeeder
Returns true if noRandom
instances are registered with this LegacyRandomSeeder.- Overrides:
isEmpty
in classSimpleRandomSeeder
- Returns:
- true if no
Random
instances are registered with this LegacyRandomSeeder.
-
clear
protected void clear()
Description copied from class:SimpleRandomSeeder
Removes all PRNGs from this seeder.- Overrides:
clear
in classSimpleRandomSeeder
-
-