public class SequentialSeedGenerator extends Object implements SeedGenerator
Following the arguments in
https://www.johndcook.com/blog/2016/01/29/random-number-generator-seed-mistakes/
this class is simply generating a sequence of numbers that are not
independent of each other but make sure that the same numbers are not used
too often.
Note that when using several instances of this class in parallel, the
SequentialSeedGenerator(long, int, int) constructor should be used.
It takes the id of the generator as well as the number of generators running
in parallel. This makes sure that all these generators are creating different
sequences of seeds.
| Modifier and Type | Field and Description |
|---|---|
private long |
nextSeed
The next seed which will be returned by this generator.
|
private long |
stepSize
The constant which is added to the last seed to create the new seed.
|
| Constructor and Description |
|---|
SequentialSeedGenerator(long seed)
Constructor if only a single instance is used.
|
SequentialSeedGenerator(long seed,
int generatorId,
int generatorCount)
Constructor which should be used if multiple generators are used in parallel.
|
| Modifier and Type | Method and Description |
|---|---|
long |
getNextSeed()
Returns the next seed of this generator.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetAsLongprivate long nextSeed
private long stepSize
public SequentialSeedGenerator(long seed)
seed - the original seed.public SequentialSeedGenerator(long seed,
int generatorId,
int generatorCount)
seed - the single original seedgeneratorId - id of this generator (< generatorCount)generatorCount - number of generators used in parallelpublic long getNextSeed()
SeedGeneratorgetNextSeed in interface SeedGeneratorCopyright © 2019–2020. All rights reserved.