PRNG 所需的建议
我正在寻找一种能够生成随机 128/256 位数字的伪随机数生成算法。安全性和加密完整性并不重要;简单性和性能高于一切。理想情况下,该算法将可在现代手机平台上使用。你能推荐这样的算法吗?可行吗?提前致谢!
I'm looking for a Pseudo-Random Number Generation algorithm capable of producing a random 128-/256-bit number. Security and cryptographic integrity are not important; simplicity and performance are valued above all else. Ideally, the algorithm will be usable on modern mobile phone platforms. Can you recommend such an algorithm? Is it feasible? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您应该尝试 SFMT:面向 SIMD 的快速 Mersenne Twister。
该 PRNG 旨在利用处理器提供的向量指令来生成 128 位整数。
有关此 PRNG 的更多信息,请查看我通过建议 SFMT 回复的另一篇文章:最佳伪随机数生成器
有关完整说明,请参阅官方页面,您还可以在其中下载 SFMT:http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index .html
You should try SFMT: SIMD-oriented Fast Mersenne Twister.
This PRNG has been designed to produce 128-bit integers, by taking advantage of vector instructions offered by processors.
For more information about this PRNG, please have a look at another post I answered to by advising SFMT: best pseudo random number generator
For a complete description, see the official page, where you can also download SFMT: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/SFMT/index.html
如果简单性是您的首要任务,请查看本文中的生成器。生成器的核心只有两行代码。它不像 Mersenne Twister 那样最先进,但它更简单并且仍然具有良好的统计特性。
If simplicity is your top priority, look at the generator in this article. The heart of the generator is just two lines of code. It's not state-of-the-art like Mersenne Twister, but it is simpler and still has good statistical properties.
http://burtleburtle.net/bob/rand/smallprng.html
那很小( 128 位状态),速度快,并且通过了目前可用的所有通用统计测试。到目前为止,这里的响应中链接到的所有其他 PRNG 都快速失败了 - 基于 MWC 的 PRNG 失败了许多测试,而 SFMT 仅失败了二进制矩阵秩/线性复杂性类型测试。
正如其他人所说,要获得 128 位,只需连接连续的 32 位输出即可。不要强行从 PRNG 状态中提取其正常输出函数产生的更多位 - 这通常会降低输出质量,有时甚至会降低很大程度。
http://burtleburtle.net/bob/rand/smallprng.html
That is small (128 bits of state) and fast and passes every general purpose statistical test available at this time. Every other PRNG linked to in the responses here so far fails tests rapid - the MWC-based PRNG fail many many tests, while SFMT fails only binary matrix rank / linear complexity type tests.
As others have said, to get 128 bits simply concatenate sequential 32 bit outputs. Do not forcibly extract more bits from a PRNGs state that its normal output function yields - that will generally degrade output quality, sometime by a large amount.