public class LongPeriodRNG extends java.lang.Object implements RandomnessSource, java.io.Serializable
IsaacRNG
,
without sacrificing speed or GWT support. If you don't already know what the period of an RNG is, this probably
isn't needed for your purposes, or many purposes in games at all. It is primarily meant for applications that need to
generate massive amounts of random numbers, more than pow(2, 64) (18,446,744,073,709,551,616), without repeating
the sequence of generated numbers. An RNG's period refers to the number of numbers it generates given a single
seed before the sequence repeats from the beginning. The period of this class is pow(2, 1024) minus 1
(179,769,313,486,231,590,772,930,519,078,902,473,361,797,697,894,230,657,273,430,081,157,732,675,805,500,963,132,708,
477,322,407,536,021,120,113,879,871,393,357,658,789,768,814,416,622,492,847,430,639,474,124,377,767,893,424,865,485,
276,302,219,601,246,094,119,453,082,952,085,005,768,838,150,682,342,462,881,473,913,110,540,827,237,163,350,510,684,
586,298,239,947,245,938,479,716,304,835,356,329,624,224,137,215). While that number is preposterously large, there's
always some application that seems to need more; if you really need more than that, look into CMWC generators, which
can have even larger state and also even larger periods. There isn't one of those in SquidLib currently, though there
is a possibility of one being added in the future. There is a 64-bit MersenneTwister, which has an even larger period
than this one, but it might not have optimal quality for some applications (notably, the game Dungeon Crawl Stone
Soup used Mersenne Twister and found that some players in a competition could predict impending random events,
despite the generator seeming bulletproof).
Constructor and Description |
---|
LongPeriodRNG()
Builds a LongPeriodRNG and initializes this class' 1024 bits of state with a random seed passed into SplitMix64,
the algorithm also used by LightRNG.
|
LongPeriodRNG(java.lang.CharSequence seed)
Builds a LongPeriodRNG and initializes this class' 1024 bits of state with the given seed, using a different
strategy depending on the seed.
|
LongPeriodRNG(long seed)
Builds a LongPeriodRNG and initializes this class' 1024 bits of state with many calls to a SplitMix64-based RNG
using a variant on seed produced by running it through PCG-Random's output step (PermutedRNG here).
|
LongPeriodRNG(long[] seed)
Builds a LongPeriodRNG and initializes this class' 1024 bits of state with the given seed as a long array, which
may or may not have 16 elements (though it is less wasteful to run this with 16 longs since that is exactly 1024
bits).
|
LongPeriodRNG(LongPeriodRNG other) |
Modifier and Type | Method and Description |
---|---|
LongPeriodRNG |
copy()
Produces a copy of this RandomnessSource that, if next() and/or nextLong() are called on this object and the
copy, both will generate the same sequence of random numbers from the point copy() was called.
|
static LongPeriodRNG[] |
createMany(int count)
Creates many LongPeriodRNG objects in an array, where each will generate a sequence of pow(2, 512) numbers that
will not overlap with other sequences in the array.
|
static LongPeriodRNG[] |
createMany(int count,
long seed)
Creates many LongPeriodRNG objects in an array, where each will generate a sequence of pow(2, 512) numbers that
will not overlap with other sequences in the array.
|
static LongPeriodRNG[] |
createMany(int count,
long[] seed)
Creates many LongPeriodRNG objects in an array, where each will generate a sequence of pow(2, 512) numbers that
will not overlap with other sequences in the array.
|
static LongPeriodRNG[] |
createMany(int count,
java.lang.String seed)
Creates many LongPeriodRNG objects in an array, where each will generate a sequence of pow(2, 512) numbers that
will not overlap with other sequences in the array.
|
boolean |
equals(java.lang.Object o) |
int |
hashCode() |
void |
jump()
This is the jump function for the generator.
|
int |
next(int bits)
Using this method, any algorithm that might use the built-in Java Random
can interface with this randomness source.
|
long |
nextLong()
Can return any long, positive or negative, of any size permissible in a 64-bit signed integer.
|
void |
reseed() |
void |
reseed(java.lang.CharSequence seed)
Reinitializes this class' 1024 bits of state with the given seed, using a different strategy depending on the seed.
|
void |
reseed(long seed)
Reinitializes this class' 1024 bits of state with the given seed passed into SplitMix64, the algorithm also used by
LightRNG.
|
void |
reseed(long[] seed)
Reinitializes this class' 1024 bits of state with the given seed as a long array, which may or may not have 16
elements (though it is less wasteful to run this with 16 longs since that is exactly 1024 bits).
|
java.lang.String |
toString() |
public LongPeriodRNG()
public LongPeriodRNG(long seed)
seed
- a 64-bit seed; can be any value.public LongPeriodRNG(java.lang.CharSequence seed)
seed
- a String (or other CharSequence) seed; can be any value, but produces the best results if it at least 16 characters longpublic LongPeriodRNG(long[] seed)
seed
- a long array seed; can have any number of elements, though 16 is idealpublic LongPeriodRNG(LongPeriodRNG other)
public void reseed()
public void reseed(long seed)
seed
- a 64-bit seed; can be any value.public void reseed(java.lang.CharSequence seed)
seed
- a String (or other CharSequence) seed; can be any value, but produces the best results if it at least 16 characters longpublic void reseed(long[] seed)
seed
- a long array seed; can have any number of elements, though 16 is idealpublic int next(int bits)
RandomnessSource
next
in interface RandomnessSource
bits
- the number of bits to be returnedpublic long nextLong()
nextLong
in interface RandomnessSource
public LongPeriodRNG copy()
copy
in interface RandomnessSource
public void jump()
public static LongPeriodRNG[] createMany(int count)
count
- the number of LongPeriodRNG objects to generate in the array.public static LongPeriodRNG[] createMany(int count, long seed)
count
- the number of LongPeriodRNG objects to generate in the array.seed
- the RNG seed that will determine the different sequences the returned LongPeriodRNG objects producepublic static LongPeriodRNG[] createMany(int count, java.lang.String seed)
count
- the number of LongPeriodRNG objects to generate in the array.seed
- the RNG seed that will determine the different sequences the returned LongPeriodRNG objects producepublic static LongPeriodRNG[] createMany(int count, long[] seed)
count
- the number of LongPeriodRNG objects to generate in the array.seed
- the RNG seed that will determine the different sequences the returned LongPeriodRNG objects producepublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
Copyright © Eben Howard 2012–2022. All rights reserved.