Class java.util.Random
All Packages Class Hierarchy This Package Previous Next Index
Class java.util.Random
Object
|
+----java.util.Random
- public class Random
- extends Object
- implements Serializable
An instance of this class is used to generate a stream of
pseudorandom 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.
- Version:
- 1.17, 07/01/98
- Author:
- Frank Yellin
- Since:
- JDK1.0
- See Also:
- random()
-
java.util.Random()
-
Creates a new random number generator.
-
java.util.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()
- Returns the next pseudorandom, uniformly distributed
double
value between 0.0
and
1.0
from this random number generator's sequence.
-
nextFloat()
- Returns the next pseudorandom, uniformly distributed
float
value between 0.0
and 1.0
from this random
number generator's sequence.
-
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.
-
nextInt()
- Returns the next pseudorandom, uniformly distributed
int
value from this random number generator's sequence.
-
nextLong()
- Returns the next pseudorandom, uniformly distributed
long
value from this random number generator's sequence.
-
setSeed(long)
- Sets the seed of this random number generator using a single
long
seed.
Random
public Random()
- Creates a new random number generator. Its seed is initialized to
a value based on the current time.
- Since:
- JDK1.0
- See Also:
- currentTimeMillis()
Random
public Random(long seed)
- Creates a new random number generator using a single
long
seed.
- Parameters:
- seed - the initial seed.
- Since:
- JDK1.0
- See Also:
- setSeed(long)
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
- Returns:
- the next pseudorandom value from this random number generator's sequence.
- Since:
- JDK1.1
nextBytes
public void nextBytes(byte bytes)
- Generates a user specified number of random bytes.
- Since:
- JDK1.1
nextDouble
public 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.
- Since:
- JDK1.0
nextFloat
public 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.
- Since:
- JDK1.0
nextGaussian
public synchronized 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
from this random number
generator's sequence.
- Since:
- JDK1.0
nextInt
public 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.
- Since:
- JDK1.0
nextLong
public 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.
- Since:
- JDK1.0
setSeed
public synchronized void setSeed(long seed)
- Sets the seed of this random number generator using a single
long
seed.
- Parameters:
- seed - the initial seed.
- Since:
- JDK1.0
All Packages Class Hierarchy This Package Previous Next Index