每个机器是否都使用相同的种子生成相同的随机数结果? [英] Does every machine generate same result of random number by using the same seed?

查看:1291
本文介绍了每个机器是否都使用相同的种子生成相同的随机数结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前被随机发生器困住了。需求规范显示了这样的示例:

I'm current stuck in the random generator. The requirement specification shows a sample like this:

Random rand = new Random(3412);

兰德结果不是直接给出的,而是用于其他性能的。

The rand result is not directly given out, but used for other performance.

我用与上面相同的代码编写了一个由种子3412产生的随机数。但是,
,其余性能的结果与样本完全不同。

I'd written the same code as above to generate a random number by a seed 3412. however, the result of the rest performance is totally different with sample.

生成的结果是518435373,我使用了在在线c#编译器上尝试过的相同代码,但是得到的生成结果是11688046,不同的结果与示例也不同。

The generating result is 518435373, I used the same code tried on the online c# compiler, but getting different result of generation which is 11688046, the rest performance result was also different with the sample.

所以我只是想知道这在不同的机器上应该有所不同吗?

So I'm just wondering is that supposed to be different in different machines?

BTW,有人吗

推荐答案

我希望任何一个实现为相同的种子提供相同的序列,但是可能涉及不同的实现。例如,一个在线C#编译器可能最终会使用Mono,我希望它与.NET中的实现有所不同。

I would expect any one implementation to give the same sequence for the same seed, but there may well be different implementations involved. For example, an "online C# compiler" may well end up using Mono, which I'd expect to have a different implementation to the one in .NET.

我不不知道实现是否在.NET的版本之间进行了更改,但是再次,这似乎完全有可能。

I don't know whether the implementations have changed between versions of .NET, but again, that seems entirely possible.

的文档href = http://msdn.microsoft.com/zh-cn/library/ctssatww.aspx> Random(int) 构造函数状态:

The documentation for the Random(int) constructor states:


为不同的Random对象提供相同的种子值会导致每个实例产生相同的随机数序列。

Providing an identical seed value to different Random objects causes each instance to produce identical sequences of random numbers.

...但是它没有指定不同版本等的含义。哎呀,它甚至没有说明x86和x64版本是否会给出相同的结果。我希望在任何一个特定的CLR实例中都能得到相同的结果(即一个进程,而不是两个并排运行的CLR,**。

... but it doesn't specify the implications of different versions etc. Heck, it doesn't even state whether the x86 and x64 versions will give the same results. I'd expect the same results within any one specific CLR instance (i.e. one process, and not two CLRs running side-by-side, either*.

如果您需要更稳定的工具,那么我将从指定的算法开始-我敢打赌,可以使用Mersenne Twister等实现。

If you need anything more stable, I'd start off with a specified algorithm - I bet there are implementations of the Mersenne Twister etc available.

这篇关于每个机器是否都使用相同的种子生成相同的随机数结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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