    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class java.util.Random

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

public class Random
extends Object
implements Serializable

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

##

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

##

next(int)
  Generates the next pseudorandom number.
nextBytes(byte[])
  Generates a user specified number of random bytes.
nextDouble()
  Generates a pseudorandom uniformally distributed `double` value between 0.0 and 1.0.
nextFloat()
  Generates a pseudorandom uniformally distributed `float` value between 0.0 and 1.0.
nextGaussian()
  Generates a pseudorandom Gaussian distributed `double` value with mean 0.0 and standard deviation 1.0.
nextInt()
  Generates a pseudorandom uniformally distributed `int` value.
nextLong()
  Generate a pseudorandom uniformally distributed `long` value.
setSeed(long)
  Sets the seed of the random number generator using a single `long` seed.

##

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

##

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

next

      protected synchronized int next(int bits)

  Generates the next pseudorandom number. Subclass should override this, as this is used by all other methods.

  Parameters:
    bits - random bits

nextBytes

      public void nextBytes(byte bytes[])

  Generates a user specified number of random bytes.

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 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