📅  最后修改于: 2020-11-14 06:22:02             🧑  作者: Mango
java.util.Random类实例用于生成伪随机数流。以下是有关Random的要点-
该类使用48位种子,可以使用线性同余公式对其进行修改。
由Random类实现的算法使用一种受保护的实用程序方法,该方法在每次调用时最多可以提供32个伪随机生成的位。
以下是java.util.Random类的声明-
public class Random
extends Object
implements Serializable
Sr.No. | Constructor & Description |
---|---|
1 |
Random() This creates a new random number generator. |
2 |
Random(long seed) This creates a new random number generator using a single long seed. |
Sr.No. | Method & Description |
---|---|
1 | protected int next(int bits)
This method generates the next pseudorandom number. |
2 | boolean nextBoolean()
This method returns the next pseudorandom, uniformly distributed boolean value from this random number generator’s sequence. |
3 | void nextBytes(byte[] bytes)
This method generates random bytes and places them into a user-supplied byte array. |
4 | double nextDouble()
This method returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator’s sequence. |
5 | float nextFloat()
This method returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator’s sequence. |
6 | double nextGaussian()
This method 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. |
7 | int nextInt()
This method returns the next pseudorandom, uniformly distributed int value from this random number generator’s sequence. |
8 | int nextInt(int n)
This method returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator’s sequence. |
9 | long nextLong()
This method returns the next pseudorandom, uniformly distributed long value from this random number generator’s sequence. |
10 | void setSeed(long seed)
This method sets the seed of this random number generator using a single long seed. |
此类从以下类继承方法-