Package java.util Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Random

Constructors , Methods

public  class  java.util.Random
    extends  java.lang.Object  
{
        // Constructors
    public Random();	
    public Random(long  seed);	

        // Methods
    public double nextDouble();	
    public float nextFloat();	
    public double nextGaussian();	
    public int nextInt();	
    public long nextLong();	
    public void setSeed(long  seed);	
}

An instance of this class is used to generate a stream of pseudo-random numbers. The class 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.

If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers.

Many applications will find the random method in class Math simpler to use.


Constructors


Random

public Random() 

Creates a new random number generator. Its seed is 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.

ParameterDescription
seed the initial seed

See Also: setSeed .


Methods


nextDouble

public double nextDouble() 

Return Value:

Returns the next pseudorandom, uniformally distributed double value between 0.0 and 1.0 from this random number generator's sequence.


nextFloat

public float nextFloat() 

Return Value:

Returns the next pseudorandom, uniformally distributed float value between 0.0 and 1.0 from this random number generator's sequence.


nextGaussian

public double nextGaussian() 

Return Value:

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.


nextInt

public int nextInt() 

Return Value:

Returns the next pseudorandom, uniformally distributed int value from this random number generator's sequence.


nextLong

public long nextLong() 

Return Value:

Returns the nextpseudorandom, uniformally distributed long value from this random number generator's sequence.


setSeed

public void setSeed(long  seed) 

Sets the seed of this random number generator using a single long seed.

ParameterDescription
seed the initial seed



Top© 1996 Sun Microsystems, Inc. All rights reserved.