Windows equivalent of /dev/random

WindowsRandom

Windows Problem Overview


Is there a way to generate random number on Windows by reading from a file or psuedo-file or character special file, the way that can be done on Linux by reading from /dev/random?

Windows Solutions


Solution 1 - Windows

Yes, it's called Microsoft CryptoAPI.

Solution 2 - Windows

This link from StingyJack's answer is good: 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.

Personally, I use rand_s() as an additional source of randomness to seed a PRNG of my choice.

Solution 3 - Windows

If you're doing .NET development you can use the RandomNumberGenerator class.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIan GView Question on Stackoverflow
Solution 1 - WindowsBill the LizardView Answer on Stackoverflow
Solution 2 - WindowscxxlView Answer on Stackoverflow
Solution 3 - WindowstvanfossonView Answer on Stackoverflow