Home > Java > JavaBase > body text

Usage of Random class in Java

Guanhui
Release: 2020-07-24 16:21:52
Original
4110 people have browsed it

Usage of Random class in Java

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template