什么是好的、快速的 PRNG(非加密安全) [英] What is a good, fast PRNG (non-cryptographically secure)

查看:36
本文介绍了什么是好的、快速的 PRNG(非加密安全)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找快速 PRNG,以便我可以快速为对象创建(半)唯一 ID.唯一性更多的是管理问题,ID重复只是极少数情况下的问题.

I'm looking for a fast PRNG so that I can quickly create (semi)unique IDs for objects. The uniqueness is more of a management problem and ID duplication is only a problem in extremely rare circumstances.

它必须尽可能快,因为性能至关重要,并且是非顺序的(如果 ID 是顺序的,则更有可能发生管理方面的错误).此外,我想避免使用较低的数字,但只需重试直到检索到足够高的数字即可轻松缓解这种情况.

It must be as fast as possible, as performance is critical, and non-sequential (if the IDs are sequential, it makes it more likely that an error on the management side can occur). Also, I'd like to avoid lower numbers, but this can easily be mitigated by just retrying until a sufficiently high number has been retrieved.

编辑我还应该补充一点,我要求 ID 为 32 位,因此 GUID 不起作用并且需要独立于平台(目前在 PC 上实现,但也需要在 Nintendo DS、PSP、PS3、Wii、Xbox 和其他平台).此外,它可能每秒被调用数千次,因此基于输入的随机数生成是不可行的.

Edit I should also add that I require the IDs to be 32bit, thus GUIDs don't work and needs to be platform independent (currently being implemented on PC, but also needs to work on Nintendo DS, PSP, PS3, Wii, Xbox and other platforms). Also, it may be called thousands of times per second, hence, input based random number generation isn't feasible.

谢谢

推荐答案

这可能有效:

自纪元以来的当前时间、线程 ID 和序列号的总和.

Sum of current time since epoch, thread id and a sequential number.

这篇关于什么是好的、快速的 PRNG(非加密安全)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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