org.jscience.measure.random
Class RandomSeedable

java.lang.Object
  extended by org.jscience.measure.random.RandomElement
      extended by org.jscience.measure.random.RandomSeedable
All Implemented Interfaces:
java.lang.Cloneable, RandomGenerator
Direct Known Subclasses:
EcuyerGenerator, LuescherGenerator, MarsagliaGenerator, MersenneTwisterGenerator

public abstract class RandomSeedable
extends RandomElement

RandomSeedable is an abstract class that extends the RandomElement class to include the ability to automatically generate a valid long seed from the clock. Thus it provides a consistent interface for seeding interchangable generators. It is reccomended that a RandomSeedable have a constructor that takes a long for a seed. For example, if you write a generator called ReallyRandom, you want to be able to do

 long seed=ReallyRandom.ClockSeed();
 RandomSeedable e=new ReallyRandom(seed);
 

this makes it convenient to keep a copy of the seed in case you want to restart the generator with the same seed some time in the future.

If one is going to use a long to generate a smaller seed by taking Clockseed() modulus another number, we reccomend that you use a prime number; this ensures that the generator would have the maximum "period" if it were started at regular issues, for instance, by a batch job. See Ranmar for an example.

Source code is available.

See Also:
Ranecu, Ranlux, Ranmar

Constructor Summary
RandomSeedable()
           
 
Method Summary
static long ClockSeed()
          Return a long integer seed calculated from the date.
static long ClockSeed(java.util.Date d)
          Return a long integer seed given a date
 
Methods inherited from class org.jscience.measure.random.RandomElement
choose, choose, clone, coin, coin, gaussian, gaussian, nextDouble, nextDouble, powlaw, uniform
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jscience.measure.random.RandomGenerator
nextDouble
 

Constructor Detail

RandomSeedable

public RandomSeedable()
Method Detail

ClockSeed

public static long ClockSeed(java.util.Date d)
Return a long integer seed given a date

Parameters:
d - a date
Returns:
a long integer seed

ClockSeed

public static long ClockSeed()
Return a long integer seed calculated from the date. Equivalent to ClockSeed(new Date());

Returns:
a long integer seed