58

Is there a way to generate random number on Windows by reading from a file or pseudo file or character special file, the way that can be done on Linux by reading from /dev/random? Not asking about various crypto API, but whether there is in Windows something akin to the Linux way.

dda
  • 6,030
  • 2
  • 25
  • 34
Ian G
  • 10,709
  • 6
  • 30
  • 34
  • 26
    I wish someone had actually answered the question that was asked. There are plenty of answers to the generic question *how can I generate random numbers on Windows*, but that is not this question. This question specifically asks about `/dev/random` which is a way to generate random numbers by reading from a “file”. This is much more interesting than just generating random numbers by calling a function. **This** is what I want to know. For the record, it’s not exactly the same, but [there are solutions for Windows and DOS](https://en.wikipedia.org/wiki//dev/random#Other_operating_systems). – Synetech Sep 13 '15 at 00:42
  • 11
    The question is on-topic and not a question for "a tool, library or favorite off-site resource". – Kijewski Jan 25 '16 at 20:12
  • 19
    This PERFECTLY VALID question is super useful, and NOT a "recommendation of a tool". Another example of the dark side of S.O. – Mr. Developerdude Nov 04 '16 at 20:05

3 Answers3

17

Yes, it's called Microsoft CryptoAPI.

laggingreflex
  • 32,948
  • 35
  • 141
  • 196
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
1

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.

cxxl
  • 4,939
  • 3
  • 31
  • 52
0

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

tvanfosson
  • 524,688
  • 99
  • 697
  • 795