es.udc.gii.common.eaf.util
Class EAFRandom

java.lang.Object
  extended by es.udc.gii.common.eaf.util.EAFRandom

public class EAFRandom
extends java.lang.Object

Random number generator.

Since:
1.0
Author:
Grupo Integrado de IngenierĂ­a (www.gii.udc.es)

Field Summary
private static long _seed
          Random seed.
private static boolean initialized
          States if this class is initialized
private static java.util.Random rand
          Random generator.
 
Constructor Summary
private EAFRandom()
          Class constructor: Singleton class.
 
Method Summary
static long getSeed()
          The seed currently used by the random number generator.
static void init()
          Initializes this random number generator.
static void init(long seed)
          Initializes this random number generator.
static boolean isInitialized()
          Test for initialization.
static boolean nextBoolean()
          Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
static void nextBytes(byte[] bytes)
          Generates random bytes and places them into a user-supplied byte array.
static double nextDouble()
          Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
static float nextFloat()
          Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.
static double nextGaussian()
          Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.
static int nextInt()
          Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.
static int nextInt(int n)
          Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
static long nextLong()
          Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_seed

private static long _seed
Random seed.


rand

private static java.util.Random rand
Random generator.


initialized

private static boolean initialized
States if this class is initialized

Constructor Detail

EAFRandom

private EAFRandom()
Class constructor: Singleton class.

Method Detail

init

public static void init()
Initializes this random number generator. The seed is taken to be the difference, measured in milliseconds, between the current time and midnight, January 1, 1970 UTC.

This method must be called before generating any random number.


init

public static void init(long seed)
Initializes this random number generator.

This method must be called before generating any random number.

Parameters:
seed - The seed for the random number generator.

nextBoolean

public static boolean nextBoolean()
Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.

Returns:
The next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
Throws:
java.lang.NullPointerException - if this class is not initialized.

nextBytes

public static void nextBytes(byte[] bytes)
Generates random bytes and places them into a user-supplied byte array. The number of random bytes produced is equal to the length of the byte array.

Parameters:
bytes - The byte array to fill with random bytes.
Throws:
java.lang.NullPointerException - If this class is not initialized or if the byte array is null.

nextDouble

public static double nextDouble()
Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.

Returns:
The next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence
Throws:
java.lang.NullPointerException - if this class is not initialized.

nextFloat

public static float nextFloat()
Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.

Returns:
The next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.
Throws:
java.lang.NullPointerException - if this class is not initialized.

nextGaussian

public static double nextGaussian()
Returns the next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0 from this random number generator's sequence.

Returns:
The next pseudorandom, Gaussian ("normally") distributed double value with mean 0.0 and standard deviation 1.0
Throws:
java.lang.NullPointerException - if this class is not initialized.

nextInt

public static int nextInt()
Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.

Returns:
The next pseudorandom, uniformly distributed int value from this random number generator's sequence.
Throws:
java.lang.NullPointerException - if this class is not initialized.

nextInt

public static int nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.

Parameters:
n - The bound on the random number to be returned. Must be positive.
Returns:
The next pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive) from this random number generator's sequence.
Throws:
java.lang.NullPointerException - if this class is not initialized.
java.lang.IllegalArgumentException - if n is not positive.

nextLong

public static long nextLong()
Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.

Returns:
The next pseudorandom, uniformly distributed long value from this random number generator's sequence
Throws:
java.lang.NullPointerException - if this class is not initialized.

isInitialized

public static boolean isInitialized()
Test for initialization.

Returns:
true if the generator is initialized. false otherwise.

getSeed

public static long getSeed()
The seed currently used by the random number generator.

Returns:
The seed currently used by the random number generator.