util.Random中的种子是什么? [英] What is seed in util.Random?

查看:81
本文介绍了util.Random中的种子是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解种子的含义. http://docs.oracle.com/javase/7/docs/api/java/util/Random.html"rel =" nofollow noreferrer> java.util.Random 吗?我已阅读为什么此代码会打印"hello world"?问题而且我仍然对种子感到困惑.有人能友善地描述我种子的实际含义吗?谢谢.

I can't understand what was the meaning of Seed in java.util.Random ? I had read Why does this code print "hello world"? question and I am still confuse about seed . Can anyone describe me kindfully what was seed actually mean ? Thanks.

setSeed()方法... seed - the initial seed是什么意思?

In documentation for setSeed() method ... what does mean seed - the initial seed ?

公共无效 setSeed (长种子)
使用单个长种子设置此随机数生成器的种子. setSeed的一般约定是,它会更改此随机数生成器对象的状态,使其处于与刚使用参数种子作为种子创建的状态完全相同的状态. setSeed方法由Random类通过将种子原子更新为
来实现 (种子^ 0x5DEECE66DL)& (((1L<< <48)-1)
并清除nextGaussian()使用的haveNextNextGaussian标志.
类Random的setSeed的实现恰好只使用给定种子的48位.但是,通常,覆盖方法可以将long自变量的所有64位用作种子值. 参数:
种子-初始种子

public void setSeed(long seed)
Sets the seed of this random number generator using a single long seed. The general contract of setSeed is that it alters the state of this random number generator object so as to be in exactly the same state as if it had just been created with the argument seed as a seed. The method setSeed is implemented by class Random by atomically updating the seed to
(seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)
and clearing the haveNextNextGaussian flag used by nextGaussian().
The implementation of setSeed by class Random happens to use only 48 bits of the given seed. In general, however, an overriding method may use all 64 bits of the long argument as a seed value. Parameters:
seed - the initial seed

如果我能完全理解seed的含义,我希望我会清楚地理解

I would expect if I can understand exactly meaning of seed , I am sure I will understand clearly to this answer.

推荐答案

伪随机数生成器生成数字序列.它 不是真正的随机,而是通常的数学计算 产生与某些理想分布相匹配的输出,并且 没有明显的模式.为了产生这样的序列, 必须处于状态存储状态,以便生成器能够生成下一个 该顺序中的数字.每次使用一些更新状态 上一步输出的一部分.

A pseudo-random number generator produces a sequence of numbers. It isn't truly random, but generally a mathematical calculation which produces an output that matches some desirable distribution, and without obvious patterns. In order to produce such a sequence, there must be state stored for the generator to be able to generate the next number in that sequence. The state is updated each time using some part of the output from the previous step.

播种显式初始化此状态. 种子"是一个开始 点,从中生长出某种东西.在这种情况下, 数字.

Seeding explicitly initialises this state. A 'seed' is a starting point, from which something grows. In this case, a sequence of numbers.

这可以用于始终生成相同的序列(通过使用 已知的常数种子),这对于确定性很有用 行为.这对于调试,对于某些网络应用程序来说非常有用, 密码学等.

This can be used either to always generate the same sequence (by using a known constant seed), which is useful for having deterministic behaviour. This is good for debugging, for some network applications, cryptography, etc.

或者,在您希望行为不可预测的情况下 (每次您运行程序或打牌游戏时总是有所不同), 您可以使用可能不断变化的数字作为种子,例如 时间.

Or, in situations where you want the behaviour to be unpredictable (always different each time you run a program, a card game perhaps), you can seed with a number likely to be continually changing, such as time.

序列的随机性"不取决于所选择的种子, 尽管它确实取决于不重新播种序列.

The 'randomness' of the sequence does not depend on the seed chosen, though it does depend on not reseeding the sequence.

来自这应该回答您的问题.

这篇关于util.Random中的种子是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆