views:

39

answers:

3

In .NET, you can generate RSA key pairs using RSACryptoServiceProvide. But is that the best option in .NET to generate truly random numbers? There are tons of other open source libraries, such as CryptoPlusPlus, that can be used to generate random number. I would like to hear from other experts' opinions. Thanks in advance for your two cents.

A: 

Classes derived from RandomNumberGenerator generate truly random numbers.

Stephen Cleary
* as random as we can get with deterministic algorithms.
Robert P
Also: From the documentation: "Application code does not directly use this class. This abstract class is provided as the base class for all cryptographic random number generators."
Robert P
Is there any proof that the derived class of RandomNumberGenerator, such as RNGCyrptowareServiceProvide, is better than library where you can feed in random seed from external source.
weilin8
Actually - depending on the machine hardware - `RNGCryptoServiceProvider` may not be dependent on "deterministic algorithms".
Stephen Cleary
@weilin8: No. On the Windows platform, the standard practice is to include a CSP if you have a source of truly random data. Otherwise (e.g., most machines), the OS will use a deterministic algorithm incorporating a wide variety of inputs to get a very close approximation of randomness. It does a better job of this than we could, so if the "random seed" is just things like mouse movements, it's definitely better left up to windows. If you do have an actual *random* source that's not a CSP for some reason, then you would be better to use it directly.
Stephen Cleary
+1  A: 
Andras Zoltan
Actually, predicting random numbers generated by the host system is pretty easy. Cheat coder have done that with many anti-cheat tools which create screenshots at random times. They just got the seed in memory and predicted the next random numbers. Ive never implemented such a method, but ive seen that working.
atamanroman
@fielding: I'll bet! Having read the excellent chapter in Practical Cryptography (http://www.schneier.com/book-practical.html) on generating Randomness it's such a minefield that it's easy to just give up! If only I had a cosmic ray detector...
Andras Zoltan
A: 

You could get them from random.org if your project allows that. That should be random enough.

atamanroman