Class java.util.Random
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class java.util.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:
random

Constructor Index

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

Method Index

 o nextDouble()
Generates a pseudorandom uniformally distributed double value between 0.0 and 1.0.
 o nextFloat()
Generates a pseudorandom uniformally distributed float value between 0.0 and 1.0.
 o nextGaussian()
Generates a pseudorandom Gaussian distributed double value with mean 0.0 and standard deviation 1.0.
 o nextInt()
Generates a pseudorandom uniformally distributed int value.
 o nextLong()
Generate a pseudorandom uniformally distributed long value.
 o setSeed(long)
Sets the seed of the random number generator using a single long seed.

Constructors

 o Random
  public Random()
Creates a new random number generator. Its seed will be initialized to a value based on the current time.
 o Random
  public Random(long seed)
Creates a new random number generator using a single long seed.
Parameters:
seed - the initial seed
See Also:
setSeed

Methods

 o setSeed
  public synchronized void setSeed(long seed)
Sets the seed of the random number generator using a single long seed.
Parameters:
seed - the initial seed
 o nextInt
  public int nextInt()
Generates a pseudorandom uniformally distributed int value.
Returns:
an integer value.
 o nextLong
  public long nextLong()
Generate a pseudorandom uniformally distributed long value.
Returns:
A long integer value
 o 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 .
 o 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 .
 o nextGaussian
  public synchronized double nextGaussian()
Generates a pseudorandom Gaussian distributed double value with mean 0.0 and standard deviation 1.0.
Returns:
a Gaussian distributed double.

All Packages  Class Hierarchy  This Package  Previous  Next  Index