Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.metacosm.framework.random
Class RandomGenerator  view RandomGenerator download RandomGenerator.java

java.lang.Object
  extended byorg.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.
 
Field Summary
private static RandomGenerator.FakedRandom random
          FakedRandom
private static RandomGenerator randomGenerator
          The instance of the class
 
Constructor Summary
private RandomGenerator()
          The constructor is private because of singleton pattern.
 
Method Summary
 int dice(int nbDice, int nbFaces)
          Rolls the given number of dice with the given number of faces.
 int die(int nbFaces)
          Rolls a die with the given number of faces.
 boolean getBoolean()
           
 byte getByte()
           
 double getDouble()
           
 float getFloat()
           
 double getGaussian()
           
 double getGaussian(double mean, double deviation)
           
static RandomGenerator getInstance()
           
 int getInt()
           
 int getInt(int n)
           
 long getLong()
           
 short getShort()
           
 void load(java.io.InputStream is)
          Loads the seed
 void save(java.io.OutputStream os)
          Saves the seed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

randomGenerator

private static RandomGenerator randomGenerator
The instance of the class


random

private static RandomGenerator.FakedRandom random
FakedRandom

Constructor Detail

RandomGenerator

private RandomGenerator()
The constructor is private because of singleton pattern.

Method Detail

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