de.cesr.uranus.core
Class URandomService

java.lang.Object
  extended by de.cesr.uranus.core.URandomService
All Implemented Interfaces:
UranusRandomService

public class URandomService
extends Object
implements UranusRandomService

Uranus - Universal RAndom NUmber Service


Field Summary
protected static URandomService randomService
           
 
Fields inherited from interface de.cesr.uranus.core.UranusRandomService
NORMAL_DEFAULT, UNIFORM_DEFAULT
 
Constructor Summary
URandomService(int seed)
          Initialise a new instance with the given random seed.
 
Method Summary
 Normal createNormal(double mean, double std)
          Create a normal distribution with the given parameters using the default random generator.
 Normal createNormal(double mean, double std, RandomEngine generator)
          Create a normal distribution with the given parameters using the given random generator.
 AbstractDistribution getDistribution(String name)
          Returns the AbstractDistribution that is registered for the given name.
 RandomEngine getGenerator(String name)
           
 Uniform getNewUniformDistribution(RandomEngine engine)
          Returns a Uniform distribution that is fed by the given RandomEngine.
 Normal getNormal()
          Returns the Normal distribution that was created at last (therefore, mean and standard deviation is not defined).
 int getSeed()
          Get the seed currently used for the default distributions.
 Uniform getUniform()
          Return the default uniform distribution.
 Uniform getUniform(double from, double to, RandomEngine engine)
           
static URandomService getURandomService()
          Return the universal random manager.
 String identifyDistribution(AbstractDistribution distribution)
          UranusRandomService#identifyDistribution(cern.jet.random.
 String identifyGenerator(RandomEngine generator)
          Identifies the name of the given RandomEngine if registered at this service.
 boolean isDebugEnabled()
          Checks if the logger of LRandomService is set to debug.
 boolean isDistributionRegistered(String name)
          Checks whether a distribution with the given name is registered.
 boolean isGeneratorRegistered(String name)
          Checks whether a generator with the given name is registered.
 void registerDistribution(AbstractDistribution dist, String name)
          Registers a custom AbstractDistribution at the given name.
 void registerGenerator(String name, RandomEngine generator)
           
static void reset()
          Resets the current instance of random service (clears distribution and generator collections).
 void setSeed(int seed)
          Sets the seed for all random number generators.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

randomService

protected static URandomService randomService
Constructor Detail

URandomService

public URandomService(int seed)
Initialise a new instance with the given random seed.

Parameters:
seed -
Method Detail

isDistributionRegistered

public boolean isDistributionRegistered(String name)
Description copied from interface: UranusRandomService
Checks whether a distribution with the given name is registered.

Specified by:
isDistributionRegistered in interface UranusRandomService
Parameters:
name - the distribution's name
Returns:
true if the distribution is registered
See Also:
UranusRandomService.isDistributionRegistered(java.lang.String)

isGeneratorRegistered

public boolean isGeneratorRegistered(String name)
Description copied from interface: UranusRandomService
Checks whether a generator with the given name is registered.

Specified by:
isGeneratorRegistered in interface UranusRandomService
Parameters:
name - the generator's name
Returns:
true if the generator is registered
See Also:
UranusRandomService.isGeneratorRegistered(java.lang.String)

getUniform

public Uniform getUniform(double from,
                          double to,
                          RandomEngine engine)
Specified by:
getUniform in interface UranusRandomService
Returns:
See Also:
de.cesr.uranus.core.UranusRandomService#getUniform(double, double, cern.jet.random.engine.RandomEngine)

getNormal

public Normal getNormal()
Description copied from interface: UranusRandomService
Returns the Normal distribution that was created at last (therefore, mean and standard deviation is not defined). Equivalent to UranusRandomService#getDistribution(UranusRandomService.NORMAL_DEFAULT). Returns null if no normal distribution has been created yet.

Specified by:
getNormal in interface UranusRandomService
Returns:
latest created normal distribution
See Also:
de.cesr.more.util.MoreRandomService#getNormal()

createNormal

public Normal createNormal(double mean,
                           double std)
Description copied from interface: UranusRandomService
Create a normal distribution with the given parameters using the default random generator.

Specified by:
createNormal in interface UranusRandomService
Returns:
normal distribution with the given parameters
See Also:
de.cesr.lara.components.util.LaraRandom#createNormal(double, double)

createNormal

public Normal createNormal(double mean,
                           double std,
                           RandomEngine generator)
Description copied from interface: UranusRandomService
Create a normal distribution with the given parameters using the given random generator.

Specified by:
createNormal in interface UranusRandomService
generator - the generator to use
Returns:
normal distribution with the given parameters
See Also:
de.cesr.lara.components.util.LaraRandom#createNormal(double, double, RandomEngine)

getUniform

public Uniform getUniform()
Description copied from interface: UranusRandomService
Return the default uniform distribution. Equivalent to LaraRandom#getDistribution(MoreRandomServicem.UNIFORM_DEFAULT).

Specified by:
getUniform in interface UranusRandomService
Returns:
the default uniform distribution
See Also:
de.cesr.more.util.MoreRandomService#getUniform()

registerDistribution

public void registerDistribution(AbstractDistribution dist,
                                 String name)
Description copied from interface: UranusRandomService
Registers a custom AbstractDistribution at the given name.

Specified by:
registerDistribution in interface UranusRandomService
See Also:
de.cesr.more.util.MoreRandomService#registerDistribution(cern.jet.random.AbstractDistribution, java.lang.String)

getNewUniformDistribution

public Uniform getNewUniformDistribution(RandomEngine engine)
Description copied from interface: UranusRandomService
Returns a Uniform distribution that is fed by the given RandomEngine. Advantage: Uses a UUniformDistributionController in case logger is debug enabled.

Specified by:
getNewUniformDistribution in interface UranusRandomService
Parameters:
engine - to fed the distribution
Returns:
uniform distribution
See Also:
de.cesr.more.util.MoreRandomService#getNewUniformDistribution(cern.jet.random.engine.RandomEngine)

setSeed

public void setSeed(int seed)
Description copied from interface: UranusRandomService
Sets the seed for all random number generators. If this method is called, a new random number generator is created, all registered distributions (also customly registered) are deleted and the default distributions are renewed.

Specified by:
setSeed in interface UranusRandomService
See Also:
de.cesr.more.util.MoreRandomService#setSeed(int)

getSeed

public int getSeed()
Description copied from interface: UranusRandomService
Get the seed currently used for the default distributions.

Specified by:
getSeed in interface UranusRandomService
Returns:
current seed
See Also:
de.cesr.more.util.MoreRandomService#getSeed()

getURandomService

public static URandomService getURandomService()
Return the universal random manager.

Returns:
the random manager

getGenerator

public RandomEngine getGenerator(String name)
Specified by:
getGenerator in interface UranusRandomService
Returns:
random engine that is associated with the given String
See Also:
UranusRandomService.getGenerator(java.lang.String)

registerGenerator

public void registerGenerator(String name,
                              RandomEngine generator)
Specified by:
registerGenerator in interface UranusRandomService
Parameters:
name - to associate the given generator with
generator - to register
See Also:
de.cesr.uranus.core.UranusRandomService#registerGenerator(java.lang.String, cern.jet.random.engine.RandomEngine)

isDebugEnabled

public boolean isDebugEnabled()
Description copied from interface: UranusRandomService
Checks if the logger of LRandomService is set to debug.

Specified by:
isDebugEnabled in interface UranusRandomService
Returns:
true if debug is enabled.

reset

public static void reset()
Resets the current instance of random service (clears distribution and generator collections).


getDistribution

public AbstractDistribution getDistribution(String name)
Description copied from interface: UranusRandomService
Returns the AbstractDistribution that is registered for the given name.

Specified by:
getDistribution in interface UranusRandomService
Returns:
registered distribution
See Also:
de.cesr.more.util.MoreRandomService#getDistribution(java.lang.String)

identifyDistribution

public String identifyDistribution(AbstractDistribution distribution)
UranusRandomService#identifyDistribution(cern.jet.random. AbstractDistribution)

Specified by:
identifyDistribution in interface UranusRandomService
Returns:

identifyGenerator

public String identifyGenerator(RandomEngine generator)
Description copied from interface: UranusRandomService
Identifies the name of the given RandomEngine if registered at this service. NOTE: The lookup is time consuming since this operation is meant to be use only for debugging purposes, and the service is optimised for other uses.

Specified by:
identifyGenerator in interface UranusRandomService
Returns:
See Also:
de.cesr.uranus.core.UranusRandomService#identifyGenerator(cern.jet.random.engine.RandomEngine)