net.charlesames.utility.common
Class SharedRandomGenerator

java.lang.Object
  extended by net.charlesames.utility.common.SharedRandomGenerator

public class SharedRandomGenerator
extends java.lang.Object

Singleton class which allows all the objects that use it to share the same random generator.

Author:
Charles Ames

Method Summary
 java.util.Random getRandom()
           
static SharedRandomGenerator getSingleton()
           
 void setSeed(long seed)
          Sets the seed value for the shared random number generator.
static void shuffle(java.util.List list)
          Shuffle the indicated List of Object instances.
static void shuffle(java.lang.Object[] array)
          Shuffle the indicated array of Object instances.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSingleton

public static SharedRandomGenerator getSingleton()
Returns:
The singleton SharedRandomGenerator instance.

getRandom

public java.util.Random getRandom()
Returns:
The shared random number generator.

setSeed

public void setSeed(long seed)
Sets the seed value for the shared random number generator. This method should only be called one by any particular thread that uses the generator.

Parameters:
seed -

shuffle

public static void shuffle(java.lang.Object[] array)
Shuffle the indicated array of Object instances. This is a static helper method. It employs the shared random number, which allows all random decisions employ the same seed.

Parameters:
array - The indicated array of Object instances

shuffle

public static void shuffle(java.util.List list)
Shuffle the indicated List of Object instances. This is a static helper method. It employs the shared random number, which allows all random decisions employ the same seed.

Parameters:
list - The indicated list of Object instances