.NET的Random随机数有多好? [英] how good is .NET's Random for making random numbers?

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

问题描述

有人做过任何测试吗?我认为它已经有了改进,因为C''

rand(),但谁知道呢。出于某种原因,它可能只是巧合,我似乎看到了模式。但即使是糟糕的兰特()

功能应该足以避免这种情况,所以我可能会看到

的东西。


Zytan

Anyone do any tests on it? I would assume it has improved since C''s
rand(), but who knows. For some reason, and it could just be
coincidence, I seem to see patterns. But even a crappy rand()
function should be good enough to avoid that, so i may be seeing
things.

Zytan

推荐答案

您是在重新使用Randomobject,还是每次都创建一个新的?注意

种子是基于时间的并且不是高清的,所以如果你在紧密的循环中使用新的

Random(),你会得到同样的批次数字。 a

static(已锁定)随机实例在某些情况下非常有用;我相信Jon在他的misc.utils中有一个StaticRand类(或类似的)。如果

你想要更多随机性然后使用加密随机,这个

不是。但它们更贵。


至于模式:在什么范围内?从统计数据来看,你偶尔会看到

类似的数字...


Marc

Are you re-using a Randomobject, or creating a new one each time? Note
that the seed is time-based and is not high-def, so if you use new
Random() in a tight loop you will get batches of the same numbers. a
static (locked) Random instance can be useful in some scenarios; I
believe Jon has a StaticRand class (or similar) in his misc.utils. If
you want more "randomness" then use a cryptographic random, which this
isn''t. But they are more expensive.

As for patters: over what range? Statistically you simply will see
similar numbers occasionally...

Marc


我总是使用我的应用程序创建一个完全一个静态随机对象,并使用DateTime.Now.Ticks将它作为种子播放。


Jon


" Zytan" < zy ********** @ gmail.comwrote in message

news:11 ******************** *@p77g2000hsh.googlegro ups.com ...
I always create a exactly one single static Random object with my app and
seed it with DateTime.Now.Ticks.

Jon

"Zytan" <zy**********@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...

有人对它进行任何测试吗?我认为它已经有了改进,因为C''

rand(),但谁知道呢。出于某种原因,它可能只是巧合,我似乎看到了模式。但即使是糟糕的兰特()

功能应该足以避免这种情况,所以我可能会看到

的东西。


Zytan
Anyone do any tests on it? I would assume it has improved since C''s
rand(), but who knows. For some reason, and it could just be
coincidence, I seem to see patterns. But even a crappy rand()
function should be good enough to avoid that, so i may be seeing
things.

Zytan


" Zytan" < zy ********** @ gmail.comwrote in message

news:11 ******************** *@p77g2000hsh.googlegro ups.com ...
"Zytan" <zy**********@gmail.comwrote in message
news:11*********************@p77g2000hsh.googlegro ups.com...

有人对它进行任何测试吗?我认为它已经有了改进,因为C''

rand(),但谁知道呢。出于某种原因,它可能只是巧合,我似乎看到了模式。但即使是糟糕的兰德()

功能也应该足够好以避免这种情况,所以我可能会看到

的东西。
Anyone do any tests on it? I would assume it has improved since C''s
rand(), but who knows. For some reason, and it could just be
coincidence, I seem to see patterns. But even a crappy rand()
function should be good enough to avoid that, so i may be seeing
things.



如果Random类不够好,你可能希望看一下

看看System.Security.Cryptography。 RNGCryptoServiceProvi der,

提供了一个加密的鲁棒随机数生成器。

If the Random class is not good enough for you, you may wish to take a
look at the System.Security.Cryptography.RNGCryptoServiceProvi der, which
provides a cryptographically-robust random number generator.


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

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