Usage of Random class in Java
The Random class in Java is mainly used to generate random numbers, usually with some other methods. Required random numbers, the methods of this class include "nextBoolean" to produce uniformly distributed boolean values, "nextDouble" to generate random Double and so on.
Method summary
boolean nextBoolean(): Returns the next pseudo-random number that is uniformly taken from this random number generator sequence The boolean value of the distribution.
double nextDouble(): Returns the next pseudo-random number, which is a double value uniformly distributed between 0.0 and 1.0 taken from this random number generator sequence.
float nextFloat(): Returns the next pseudo-random number, which is a uniformly distributed float value between 0.0 and 1.0 taken from this random number generator sequence.
int nextInt(): Returns the next pseudo-random number, which is a uniformly distributed int value in the sequence of this random number generator.
int nextInt(int n): Returns a pseudo-random number, which is a uniformly distributed int value between 0 (inclusive) and the specified value n (exclusive) taken from this random number generator sequence.
long nextLong(): Returns the next pseudorandom number, which is a uniformly distributed long value taken from this random number generator sequence.
void setSeed(long seed): Sets the seed of this random number generator using a single long seed.
Recommended tutorial: "Java Tutorial"
The above is the detailed content of Usage of Random class in Java. For more information, please follow other related articles on the PHP Chinese website!