Java的RNG(使用种子)是否与平台无关? [英] Is Java's RNG (using seeds) platform-independent?

查看:126
本文介绍了Java的RNG(使用种子)是否与平台无关?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

提前道歉,询问(看似显而易见的)问题。我没有在网上找到答案,所以我想我会问:

Apologies in advance for asking a (seemingly obvious) question. I haven't found an answer online, so I figured I'd ask:

Java的Util.Random平台是独立的吗?

例如, new Random(50)将在* nix中产生完全相同的随机数序列Windows系统?

For Example, is new Random(50) going to produce the exact same sequence of random numbers in both *nix and Windows systems?

推荐答案

来自文档


如果有两个实例<使用相同的种子创建code> Random ,并为每个种子创建相同的方法调用序列,它们将生成并返回相同的数字序列。为了保证此属性,为类 Random 指定了特定的算法。为了Java代码的绝对可移植性,Java实现必须使用此处显示的所有算法用于类 Random

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.

这篇关于Java的RNG(使用种子)是否与平台无关?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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