|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectvooga.engine.resource.random.Randomizer
public class Randomizer
Manages random number generation for the game using a primary random number generator. The majority if not all of the game functions should use the primary random number generator in order to facilitate reproducibility and replayability for game sessions. The available random value are: integers uniformly distributed across the full range integers uniformly distributed across a range of 0 to some maximum value integers uniformly distributed across a range with a minimum and maximum value longs uniformly distributed across the full range longs uniformly distributed across a range of 0 to some maximum value longs uniformly distributed across a range with a minimum and maximum value doubles uniformly distributed across from 0 inclusive to 1 exclusive doubles uniformly distributed across a range of 0 inclusive to some maximum value exclusive doubles uniformly distributed across a range with a minimum inclusive and maximum exclusive value floats uniformly distributed across from 0 inclusive to 1 exclusive floats uniformly distributed across a range of 0 inclusive to some maximum value exclusive floats uniformly distributed across a range with a minimum inclusive and maximum exclusive value booleans doubles in a standardized Gaussian distribution Functionality is included for retrieving use of past game seeds in order to allow for recreation of past random variable usage. Seeds can either be retrieved based on unique string ids or using a chronological list of used seeds which also includes unnamed seeds and the number of times each seed was used. The most basic seed reuse functionality of starting over using the current seed is also available. If at any point random number generation is required but the use of the primary number generator would compromise the replayability, secondary random number generators are available. For instance, particle effects based on random movement might require random number generation, but the exact replication of the movement of the particles is not required for replayability. Furthermore, using the primary number generator could cause potential problems in off-setting future random number values if somehow the particle requires the use of one more random number in a replay. To avoid this issue, one could create implement a secondary random number generator, called a random path, which is referred to by a unique string id. Then, in this example, particle movement could use that USID to create a sequence of random variables on a the new random path without affecting the primary random number generator. These random paths do not have the same retrieval functionality as the primary generator. The random number generation is based on the java.util.Random class.
Constructor Summary | |
---|---|
Randomizer()
|
Method Summary | |
---|---|
static void |
createRandomPath(java.lang.String pathID)
Create a new random path/secondary random number generator referenced by a unique string id and seeded with a value based on the current system time. |
static void |
createRandomPath(java.lang.String pathID,
java.lang.Long seed)
Create a new random path/secondary random number generator referenced by a unique string id and seeded with a given value |
static long |
generateSeed()
Returns a value to be used for seeding based on the current system time. |
static java.util.List<java.lang.String> |
getUsedSeedNames()
Return the USIDs of all the seeds used this game in chronological order. |
static java.lang.String |
getUsedSeedsCSV()
Returns a comma separated value String of the last used seed values and the corresponding unique string IDs of those seeds in chronological order. |
static java.util.List<java.lang.Long> |
getUsedSeedVals()
Return the last used seed values seeded to the primary random number generator in chronological order. |
static boolean |
nextBoolean()
Returns a random boolean using the primary number generator. |
static boolean |
nextBoolean(java.lang.String pathID)
Returns a random boolean using the a specified random path |
static double |
nextDouble(double... range)
Returns a random double using the primary number generator. |
static double |
nextDouble(java.lang.String pathID,
double... range)
Returns a random double using a specified random path. |
static float |
nextFloat(float... range)
Returns a random float using the primary number generator. |
static float |
nextFloat(java.lang.String pathID,
float... range)
Returns a random float using a specified random path. |
static double |
nextGaussian()
Returns a random double from a standardized Gaussian distribution using the primary random number generator. |
static double |
nextGaussian(java.lang.String pathID)
Returns a random double from a standardized Gaussian distribution using a specified random path. |
static int |
nextInt(java.lang.Integer... range)
Returns a random integer using the primary number generator. |
static int |
nextInt(java.lang.String pathID,
java.lang.Integer... range)
Returns a random integer using a specified random path. |
static long |
nextLong(long... range)
Returns a random long using the primary number generator. |
static long |
nextLong(java.lang.String pathID,
long... range)
Returns a random long using a specified random path. |
static void |
resetSeed()
Reset the primary random number generator to start over using its current seed value which allows replication of the sequence of random numbers used since the last time the seed was changed. |
static void |
resetSeed(java.lang.String seedUSID)
Reset the primary random number generator to start over using its the seed value corresponding to a unique string id which allows replication of the sequence of random numbers from that seed. |
static void |
setSeed(long seed)
Set the seed of the primary random number generator to the given seed value. |
static void |
setSeed(long seed,
java.lang.String seedUSID)
Set the seed of the primary random number generator to the given seed value which will be retrievable using a unique string identification for the seed. |
static void |
setSeed(long seed,
java.lang.String seedUSID,
boolean overwrite)
Set the seed of the primary random number generator to the given seed value which will be retrievable using a unique string identification for the seed. |
static void |
setSeed(java.lang.String seedUSID)
Set the seed of the primary random number generator to some seed value which will be retrievable using a unique string identification for the seed. |
static void |
setSeed(java.lang.String seedUSID,
boolean overwrite)
Set the seed of the primary random number generator to some seed value which will be retrievable using a unique string identification for the seed. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Randomizer()
Method Detail |
---|
public static void createRandomPath(java.lang.String pathID)
pathID
- the unique string identification of the random pathpublic static void createRandomPath(java.lang.String pathID, java.lang.Long seed)
pathID
- the unique string identification of the random pathseed
- the value to seed the random number generator withpublic static long generateSeed()
public static void setSeed(long seed)
seed
- the value to seed the primary number generatorpublic static void setSeed(java.lang.String seedUSID)
seedUSID
- unique string ID for the seedpublic static void setSeed(java.lang.String seedUSID, boolean overwrite)
seedUSID
- unique string ID for the seedpublic static void setSeed(long seed, java.lang.String seedUSID)
seed
- the value to seed the primary number generatorseedUSID
- unique string ID for the seedpublic static void setSeed(long seed, java.lang.String seedUSID, boolean overwrite)
seed
- the value to seed the primary number generatorseedUSID
- unique string ID for the seedpublic static void resetSeed()
public static void resetSeed(java.lang.String seedUSID)
seedUSID
- the unique string id of the seed to set the generator topublic static java.util.List<java.lang.String> getUsedSeedNames()
public static java.util.List<java.lang.Long> getUsedSeedVals()
public static java.lang.String getUsedSeedsCSV()
public static int nextInt(java.lang.Integer... range) throws RandomizerException
range
- leave blank for random int, or specify a maximum, or specify a
range
RandomizerException
public static long nextLong(long... range) throws RandomizerException
range
- leave blank for random long, or specify a maximum, or specify
a range
RandomizerException
public static double nextDouble(double... range) throws RandomizerException
range
- leave blank for random double, or specify a maximum, or
specify a range
RandomizerException
public static float nextFloat(float... range) throws RandomizerException
range
- leave blank for random float, or specify a maximum, or specify
a range
RandomizerException
public static boolean nextBoolean()
public static double nextGaussian()
public static int nextInt(java.lang.String pathID, java.lang.Integer... range) throws RandomizerException
pathID
- the unique string id of the desired random pathrange
- leave blank for random int, or specify a maximum, or specify a
range
RandomizerException
public static long nextLong(java.lang.String pathID, long... range) throws RandomizerException
pathID
- the unique string id of the desired random pathrange
- leave blank for random long, or specify a maximum, or specify
a range
RandomizerException
public static double nextDouble(java.lang.String pathID, double... range) throws RandomizerException
pathID
- the unique string id of the desired random pathrange
- leave blank for random double, or specify a maximum, or
specify a range
RandomizerException
public static float nextFloat(java.lang.String pathID, float... range) throws RandomizerException
pathID
- the unique string id of the desired random pathrange
- leave blank for random float, or specify a maximum, or specify
a range
RandomizerException
public static boolean nextBoolean(java.lang.String pathID)
pathID
- the unique string id of the desired random path
public static double nextGaussian(java.lang.String pathID)
pathID
- the unique string id of the desired random path
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |