java.util
Class Random

java.lang.Object
  |
  +--java.util.Random

public class Random
extends Object

A Random class generates a stream of pseudo-random numbers.

To create a new random number generator, use one of the following methods:

     new Random()       
     new Random(long seed)
 
The form new Random() initializes the generator to a value based on the current time. The form new Random(long seed) seeds the random number generator with a specific initial value; use this if an application requires a repeatable stream of pseudo-random numbers.

The random number generator uses a 48-bit seed, which is modified using a linear congruential formula. See Donald Knuth, The Art of Computer Programming, Volume 2, Section 3.2.1. The generator's seed can be reset with the following method:

    setSeed(long seed)
 
To create a pseudo-random number, use one of the following functions:
    nextInt()
    nextLong()
    nextFloat()
    nextDouble()
    nextGaussian()
 

See Also:
Math.random()

Constructor Summary
Random()
          Creates a new random number generator.
Random(long seed)
          Creates a new random number generator using a single long seed.
 
Method Summary
 double nextDouble()
          Generates a pseudorandom uniformally distributed double value between 0.0 and 1.0.
 float nextFloat()
          Generates a pseudorandom uniformally distributed float value between 0.0 and 1.0.
 double nextGaussian()
          Generates a pseudorandom Gaussian distributed double value with mean 0.0 and standard deviation 1.0.
 int nextInt()
          Generates a pseudorandom uniformally distributed int value.
 long nextLong()
          Generate a pseudorandom uniformally distributed long value.
 void setSeed(long seed)
          Sets the seed of the random number generator using a single long seed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Random

public Random()
Creates a new random number generator. Its seed will be initialized to a value based on the current time.


Random

public Random(long seed)
Creates a new random number generator using a single long seed.

Parameters:
seed - the initial seed
See Also:
setSeed(long)
Method Detail

setSeed

public void setSeed(long seed)
Sets the seed of the random number generator using a single long seed.

Parameters:
seed - the initial seed

nextInt

public int nextInt()
Generates a pseudorandom uniformally distributed int value.

Returns:
an integer value.

nextLong

public long nextLong()
Generate a pseudorandom uniformally distributed long value.

Returns:
A long integer value

nextFloat

public float nextFloat()
Generates a pseudorandom uniformally distributed float value between 0.0 and 1.0.

Returns:
a float between 0.0 and 1.0 .

nextDouble

public double nextDouble()
Generates a pseudorandom uniformally distributed double value between 0.0 and 1.0.

Returns:
a float between 0.0 and 1.0 .

nextGaussian

public double nextGaussian()
Generates a pseudorandom Gaussian distributed double value with mean 0.0 and standard deviation 1.0.

Returns:
a Gaussian distributed double.