bluegammon.logic
Class Rand

java.lang.Object
  extended bybluegammon.logic.Rand

public class Rand
extends java.lang.Object

Global random generator. It must be global so all methods needing random values accesses the same methods. This is because we want similar behaviour on both devices in a remote game, which is achieved by agreeing on a mutual seed.

Author:
Peter Andersson

Method Summary
static int loadSeed(java.io.DataInputStream dis)
          Loads the seed into random generator.
static int random()
          Returns a random integer ranging from Integer.MIN_VALUE to Integer.MAX_VALUE.
static float randomFloat()
          Returns a random float ranging from -1.0f to 1.0f.
static int saveSeed(java.io.DataOutputStream dos)
          Writes the seed used by random generator.
static void setRandomSeed(long seed)
          Sets the seed of the random generator.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

setRandomSeed

public static void setRandomSeed(long seed)
Sets the seed of the random generator.

Parameters:
seed - The seed of the random generator.

random

public static int random()
Returns a random integer ranging from Integer.MIN_VALUE to Integer.MAX_VALUE.

Returns:
A random integer value.

randomFloat

public static float randomFloat()
Returns a random float ranging from -1.0f to 1.0f.

Returns:
A random float value.

loadSeed

public static int loadSeed(java.io.DataInputStream dis)
                    throws java.io.IOException
Loads the seed into random generator.

Parameters:
dis - The stream to read from.
Returns:
Number of bytes read.
Throws:
java.io.IOException - if loading failed

saveSeed

public static int saveSeed(java.io.DataOutputStream dos)
                    throws java.io.IOException
Writes the seed used by random generator.

Parameters:
dos - The stream to write to,
Returns:
Number of bytes written.
Throws:
java.io.IOException - if saving failed