简体   繁体   English

Java的RNG(使用种子)是否与平台无关?

[英]Is Java's RNG (using seeds) platform-independent?

Apologies in advance for asking a (seemingly obvious) question. 提前道歉,问一个(看似很明显的)问题。 I haven't found an answer online, so I figured I'd ask: 我没有在网上找到答案,所以我想我会问:

Is Java's Util.Random platform-independent? Java的Util.Random平台是独立的吗?

For Example, is new Random(50) going to produce the exact same sequence of random numbers in both *nix and Windows systems? 例如, new Random(50)会在* nix和Windows系统中产生完全相同的随机数序列?

From the docs : 来自文档

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. 如果使用相同的种子创建两个Random实例,并且对每个实例都进行相同的方法调用序列,则它们将生成并返回相同的数字序列。 In order to guarantee this property, particular algorithms are specified for the class Random . 为了保证此属性,为Random类指定了特定的算法。 Java implementations must use all the algorithms shown here for the class Random , for the sake of absolute portability of Java code. 为了Java代码的绝对可移植性,Java实现必须使用此处显示的所有算法用于Random类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM