public class ShuffledIntSequence extends LowStorageShuffler implements java.io.Serializable
next()
on a ShuffledIntSequence
to get the next distinct int in the shuffled ordering; next() will re-shuffle the sequence if it runs out of distinct
possible results. You can go back to the previous item with previous()
, which is allowed to go earlier than
the first result generated (it will jump back to what is effectively the previous shuffled sequence). You can restart
the sequence with LowStorageShuffler.restart()
to use the same sequence over again (which doesn't make much sense here, since
this makes many sequences by re-shuffling), or restart(long)
to use a different seed (the bound is fixed).
LowStorageShuffler.round(long, long)
method used here reuses the CrossHash.Water.wow(long, long)
method; it acts like an unbalanced, irreversible PRNG with two states, and that turns out to be just fine for a
Feistel network. This also uses a different seed for each round.
LowStorageShuffler
, changing it from producing a unique set of ints once, to producing
many sets of ints one after the next.
Modifier and Type | Field and Description |
---|---|
protected long |
seed |
Constructor and Description |
---|
ShuffledIntSequence()
Constructs a ShuffledIntSequence with a random seed and a bound of 10.
|
ShuffledIntSequence(int bound)
Constructs a ShuffledIntSequence with the given exclusive upper bound and a random seed.
|
ShuffledIntSequence(int bound,
long seed)
Constructs a ShuffledIntSequence with the given exclusive upper bound and int seed.
|
Modifier and Type | Method and Description |
---|---|
int |
next()
Gets the next distinct int in the sequence, shuffling the sequence if it has been exhausted so it never runs out.
|
int |
previous()
Gets the previous returned int from the sequence (as yielded by
next() ), restarting the sequence in a
correctly-ordered way if it would go to before the "start" of the sequence (it is actually close to infinite both
going forwards and backwards). |
void |
restart(long seed)
Starts the sequence over, but can change the seed (completely changing the sequence).
|
copy, deserializeFromString, encode, equals, hashCode, restart, round, serializeToString
public ShuffledIntSequence()
public ShuffledIntSequence(int bound)
bound
- how many distinct ints this can returnpublic ShuffledIntSequence(int bound, long seed)
bound
- how many distinct ints this can returnseed
- any int; will be used to get several seeds used internallypublic int next()
next
in class LowStorageShuffler
public int previous()
next()
), restarting the sequence in a
correctly-ordered way if it would go to before the "start" of the sequence (it is actually close to infinite both
going forwards and backwards).previous
in class LowStorageShuffler
public void restart(long seed)
seed
is the same
as the seed given in the constructor, this will use the same sequence, acting like LowStorageShuffler.restart()
.restart
in class LowStorageShuffler
seed
- any int; will be used to get several seeds used internallyCopyright © Eben Howard 2012–2022. All rights reserved.