Class BufferedSeedGenerator
- java.lang.Object
-
- io.github.pr0methean.betterrandom.seed.BufferedSeedGenerator
-
- All Implemented Interfaces:
SeedGenerator
,Serializable
public class BufferedSeedGenerator extends Object implements SeedGenerator
A seed generator that wraps another, maintaining a buffer of previously-fetched bytes to reduce the number of I/O calls. The buffer is only used when the requested seed is strictly smaller than the buffer.- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from interface io.github.pr0methean.betterrandom.seed.SeedGenerator
EMPTY_SEED
-
-
Constructor Summary
Constructors Constructor Description BufferedSeedGenerator(SeedGenerator delegate, int size)
Creates an instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(Object o)
void
generateSeed(byte[] output)
Generates a seed value for a random number generator in an existing array.int
hashCode()
boolean
isWorthTrying()
Returns true if we cannot determine quickly (i.e.String
toString()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.pr0methean.betterrandom.seed.SeedGenerator
generateSeed
-
-
-
-
Constructor Detail
-
BufferedSeedGenerator
public BufferedSeedGenerator(SeedGenerator delegate, int size)
Creates an instance.- Parameters:
delegate
- the SeedGenerator to wrapsize
- the buffer size in bytes
-
-
Method Detail
-
generateSeed
public void generateSeed(byte[] output) throws SeedException
Description copied from interface:SeedGenerator
Generates a seed value for a random number generator in an existing array.- Specified by:
generateSeed
in interfaceSeedGenerator
- Parameters:
output
- The array that is to be populated with the seed.- Throws:
SeedException
- If a seed cannot be generated for any reason.
-
isWorthTrying
public boolean isWorthTrying()
Description copied from interface:SeedGenerator
Returns true if we cannot determine quickly (i.e. without I/O calls) that this SeedGenerator would throw aSeedException
ifSeedGenerator.generateSeed(int)
orSeedGenerator.generateSeed(byte[])
were being called right now.- Specified by:
isWorthTrying
in interfaceSeedGenerator
- Returns:
- true if this SeedGenerator will get as far as an I/O call or other slow operation in attempting to generate a seed immediately.
-
-