Random是什么用法?各位大哥能解释一下吗?

asiaec 2002-01-16 11:03:13
RT
...全文
80 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoyixiao 2002-01-16
  • 打赏
  • 举报
回复
伪随机发生器
xmvigour 2002-01-16
  • 打赏
  • 举报
回复
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. In order to guarantee this property, particular algorithms are specified for the class Random. Java implementations must use all the algorithms shown here for the class Random, for the sake of absolute portability of Java code. However, subclasses of class Random are permitted to use other algorithms, so long as they adhere to the general contracts for all the methods.

The algorithms implemented by class Random use a protected utility method that on each invocation can supply up to 32 pseudorandomly generated bits.

Many applications will find the random method in class Math simpler to use.

Since:

JDK1.0

See Also:

Math.random(), Serialized Form


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
protected int next(int bits)
Generates the next pseudorandom number.
boolean nextBoolean()
Returns the next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
void nextBytes(byte[] bytes)
Generates random bytes and places them into a user-supplied byte array.
double nextDouble()
Returns the next pseudorandom, uniformly distributed double value between 0.0 and 1.0 from this random number generator's sequence.
float nextFloat()
Returns the next pseudorandom, uniformly distributed float value between 0.0 and 1.0 from this random number generator's sequence.
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.
int nextInt()
Returns the next pseudorandom, uniformly distributed int value from this random number generator's sequence.
int nextInt(int n)
Returns a pseudorandom, uniformly distributed int value between 0 (inclusive) and the specified value (exclusive), drawn from this random number generator's sequence.
long nextLong()
Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.
void setSeed(long seed)
Sets the seed of this random number generator using a single long seed.


23,407

社区成员

发帖
与我相关
我的任务
社区描述
Java 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧