在 .NET 中播种随机数生成器 [英] Seeding a random number generator in .NET

查看:58
本文介绍了在 .NET 中播种随机数生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 伪随机数生成器 (PRNG),它使用六个 UInt32s 作为状态.我需要想出一个合理的方法来播种它.两个明显的可能性是:1) 使用 System.Random 生成六个随机数并将它们用作种子;2) 使用 Guid.NewGuid() 生成两个 GUID.哪个更好?

I have a pseudorandom number generator (PRNG) with nice properties which uses six UInt32s as state. I need to come up with a reasonable way to seed it. Two obvious possibilities are: 1) generate six random numbers using System.Random and use them as seeds; 2) generate two GUIDs with Guid.NewGuid(). Which would be better?

不需要加密安全性.

推荐答案

如果需要UInt32,那Random更方便吗?只是 Next()Next()Next() 等等(和转换)...(使用相同的 Random 实例 - 不要每次都创建 new Random().

If it needs UInt32, then Random is more convenient? just Next(), Next(), Next() etc (and cast)... (use the same Random instance however - don't create new Random() each time).

这取决于是否提供足够的随机性的意图.既然这只是种子,应该没问题...

It depends on what the intent is as to whether this offers enough randomness. Since this is just the seed, it should be OK...

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

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