Daniel wrote:
Hey guys
Using Random(), how random is it, is it possible to be predicted? I
have a requirement for a very good random number generator. I was
doing something such as:
Random randomSeed = new
Random((int)_seedTimer.ElapsedTicks); _random = new
Random(randomSeed.Next(0,99999999));
return random.Next(min, max);
But i am finding that in some cases the same sets of numbers appear or
regularly occur? any idea why? Any tips on better methods for truly
random numbers?
As others have replied, Random instances with time corellated seeds will
generate time corellated values. The Random class is a simple linear
congruential generator [1]. If you need random numbers for a security
purpose (e.g. encryption keys), then you need to use a cryptographically
strong random number generator. One such strong random number generator is
exposed by the System.Security.Cryptography.RNGCryptoServiceProvi der class
[2].
-cd
[1]
http://en.wikipedia.org/wiki/Linear_...ial_Generators
[2]
http://msdn2.microsoft.com/en-us/lib...eprovider.aspx