java.lang.Object
org.metacosm.framework.random.RandomGenerator
- All Implemented Interfaces:
- org.metacosm.framework.persistence.Persistent, java.io.Serializable
- public final class RandomGenerator
- extends java.lang.Object
- implements org.metacosm.framework.persistence.Persistent
Randomizer for the game
It's a Singleton OOD pattern.
|
Nested Class Summary |
(package private) class |
RandomGenerator.FakedRandom
We need to overload the original java.util.Random
to be able to get the seed to reproduce a game later. |
|
Constructor Summary |
private |
RandomGenerator()
The constructor is private because of singleton pattern. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
randomGenerator
private static RandomGenerator randomGenerator
- The instance of the class
random
private static RandomGenerator.FakedRandom random
- FakedRandom
RandomGenerator
private RandomGenerator()
- The constructor is private because of singleton pattern.
getInstance
public static RandomGenerator getInstance()
die
public int die(int nbFaces)
throws java.lang.IllegalArgumentException
- Rolls a die with the given number of faces.
dice
public int dice(int nbDice,
int nbFaces)
throws java.lang.IllegalArgumentException
- Rolls the given number of dice with the given number of faces.
Example: dice(3,6) = 3D6
getInt
public int getInt()
getInt
public int getInt(int n)
getByte
public byte getByte()
getShort
public short getShort()
getLong
public long getLong()
getBoolean
public boolean getBoolean()
getFloat
public float getFloat()
getDouble
public double getDouble()
getGaussian
public double getGaussian()
getGaussian
public double getGaussian(double mean,
double deviation)
load
public void load(java.io.InputStream is)
throws java.io.IOException,
java.lang.NumberFormatException
- Loads the seed
- Specified by:
load in interface org.metacosm.framework.persistence.Persistent
save
public void save(java.io.OutputStream os)
throws java.io.IOException
- Saves the seed.
- Specified by:
save in interface org.metacosm.framework.persistence.Persistent