java - 为什么 Random.setSeed 的 Java 实现将参数与 0x5DEECE66DL 异或?

标签 java random

参见 http://docs.oracle.com/javase/7/docs/api/java/util/Random.html#setSeed(long) .代码 xors 种子与乘数减少它 mod 2^48 之前。为什么不直接减少传递的种子 mod 2^48? C 等效的 seed48 不执行异或。

最佳答案

您可以在这里找到一本不错的读物:java.util.Random’s Magic Number 0x5DEECE66D .

还有一段话:

The analysis says it was chosen simply because researchers determined empirically 
that it produces a sequence of values satisfying various randomness tests

还有这个Document也给了魔术数字一个机会。

还有一个引用:

I then tried a search for the decimal value, excluding Java, and found the answer in some class notes:

http://nut.bu.edu/~youssef/py502/monte_carlo_supplement.ps http://www.inf.ethz.ch/personal/gaertner/texts/own_work/random_matrices.pdf

and in some computer documentation:

http://developer.apple.com/documentation/Darwin/Reference/ManPages/html/_rand48.3.html

The Youssef notes say:

... I can only say that 25214903917_LONG and 11_LONG have
apparently been chosen by passing a battery of such [meaning
Marsaglia's DIEHARD] tests.

... Even in the case of the 48-bit generators we are discussing
today, cas26 will generate them all in a month or two of CPU time
and then start to repeat.

关于java - 为什么 Random.setSeed 的 Java 实现将参数与 0x5DEECE66DL 异或?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14264196/

相关文章:

java - Android 主屏幕快捷方式权限错误

java - 在适配器中获取 Activity - Java 中的 Android studio

python - 在 python 中获取 1 到 100 万之间的随机数的最快方法

java - 如何在 java 中随机更改窗口背景的颜色?

Python if-elif 语句顺序

java - Android 服务连接泄露

java - 在有限的时间内运行一段代码

objective-c - 确保 random() 不返回 0?

python - 向量化 np.random.binomial 以接受多维数组

java - 数学和数组