Class StepSequence
java.lang.Object
io.github.olyutorskii.aletojio.rng.dull.StepSequence
- All Implemented Interfaces:
RndInt32
Step progression sequence generator.
X(n) = start + step * n
If a suitable step is selected, it can be compromised as a quasi-random number generator.
Using large prime numbers other than 2 for step would give a long period.
Integer.MAX_VALUE
is followed by Integer.MIN_VALUE
.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Prime number near equal golden ratio of Integer.MAX. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StepSequence
Create simple counter.static StepSequence
Create Quasi-random generator.int
Return next random number as 32bit int with random sign-bit.
-
Field Details
-
PRIME_STEP
public static final int PRIME_STEPPrime number near equal golden ratio of Integer.MAX.Using this number for step yields sparse results that are hard to approximate with rational numbers.
Ref : Integer.MAX * (3-SQRT(5)) = 1640531525
- See Also:
-
-
Constructor Details
-
StepSequence
public StepSequence(int start, int step) Constructor.output sequence will be {start, start+step, start+step*2, start+step*3, ...}
Overflow is ignored.
- Parameters:
start
- start valuestep
- step value
-
-
Method Details
-
createCounter
Create simple counter.{0, 1, 2, ...}
- Returns:
- counter
-
createQuasiRandom
Create Quasi-random generator.Quasi-random generator outputs extremely uniform random numbers.
- Returns:
- random generator
- See Also:
-
nextInt32
public int nextInt32()Return next random number as 32bit int with random sign-bit.
-