跨平台的随机数发生器 [英] Crossplatform random number generator

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

问题描述

当你需要能够从种子产生一个随机数,并保证它可以在不同版本的.NET框架和Mono框架相同的号码,如,以及在不同的体系结构(86,64)你该怎么办?

When you need to be able to generate a random number from a seed, and guarantee it be the same number across different versions of the .NET Framework and Mono Framework, as-well as across different architectures (x86, x64), what do you do?

我目前正在考虑存储数百万个随机的字节用作临时解决这个问题的文件,但我认为有可能是一个更好的方式(希望不会太复杂得多)。

I'm presently considering storing millions of random bytes in a file for use as a temporary solution to this problem, but I think there's probably a better way (hopefully not too much more complicated).

推荐答案

如果你需要一个真正便携的实现,最好的办法可能是只是使用自定义随机数发生器,比如这个梅森倍捻机实施或的Colin格林的快速随机数发生器。通过控制实现,你能保证你会得到相同的结果给出任何平台上相同的种子。

If you need a truly portable implementation, the best option would probably be to just use a custom random number generator, such as this Mersenne Twister implementation or Colin Green's Fast Random Number Generator. By controlling the implementation, you can guarantee that you'll get the same results given the same seed on any platform.

这篇关于跨平台的随机数发生器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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