Windows 相当于 /dev/random
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/191335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows equivalent of /dev/random
提问by Ian G
Is there a Windows equivalent of Linux's /dev/random?
是否有 Windows 等价于 Linux 的/dev/random?
采纳答案by Bill the Lizard
Yes, it's called Microsoft CryptoAPI.
是的,它被称为Microsoft CryptoAPI。
回答by cxxl
This link from StingyHyman's answer is good: http://en.wikipedia.org/wiki/CryptGenRandom
这个来自 StingyHyman 的回答的链接很好:http: //en.wikipedia.org/wiki/CryptGenRandom
Microsoft C++ Visual Studio since 2005 offers rand_s()
which works on Windows XP and up. It is based on RtlGenRandom
(as are CryptoAPI's PRNG functions), whose inner workings are not made public. It seems in XP there were some weaknesses that have since been fixed.
自 2005 年以来,Microsoft C++ Visual Studio 提供rand_s()
适用于 Windows XP 及更高版本。它基于RtlGenRandom
(与 CryptoAPI 的 PRNG 函数一样),其内部工作原理未公开。似乎在 XP 中存在一些已修复的弱点。
Personally, I use rand_s()
as an additional source of randomness to seed a PRNG of my choice.
就我个人而言,我使用rand_s()
作为随机性的额外来源来播种我选择的 PRNG。
回答by tvanfosson
If you're doing .NET development you can use the RandomNumberGeneratorclass.
如果您正在进行 .NET 开发,您可以使用RandomNumberGenerator类。