C#/ Java的随机数 [英] C#/Java Number Randomization

查看:224
本文介绍了C#/ Java的随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能,从.NET,以模仿Java使用的确切随机?我有一颗种子,而我希望能够创建一个随机数时收到在C#和Java相同的结果。

Is it possible, from .NET, to mimic the exact randomization that Java uses? I have a seed, and I would like to be able to recieve the same results in both C# and Java when creating a random number.

推荐答案

如果您有 java.util.Random中的类的源代码,为您的Java实现,你可以很容易移植到.NET。

If you have the source code of the java.util.Random class for your Java implementation, you can easily port it to .NET.

<击>如果您需要这两个应用程序(Java和.NET)使用某个随机数生成器,你最好实现一个在这两个平台上,并用它来代替,为系统提供的版本可能会改变它的行为作为更新的结果。(貌似Java规范准确地描述其PRNG的行为。)

If you require both applications (Java and .NET) to use a certain random number generator, you'd better implement one in both platforms and use it instead, as the system provided version might change its behavior as a result of an update.(Looks like the Java specification precisely describes the behavior of its PRNG.)

这篇关于C#/ Java的随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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