|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Random
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()
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 |
public Random()
public Random(long seed)
long
seed.
seed
- the initial seedsetSeed(long)
Method Detail |
public void setSeed(long seed)
long
seed.
seed
- the initial seedpublic int nextInt()
int
value.
public long nextLong()
long
value.
public float nextFloat()
float
value between 0.0 and 1.0.
float
between 0.0 and 1.0 .public double nextDouble()
double
value between 0.0 and 1.0.
float
between 0.0 and 1.0 .public double nextGaussian()
double
value with mean 0.0 and standard
deviation 1.0.
double
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |