How do I generate a random integer in C#?
I wanted to add a cryptographically secure version:
RNGCryptoServiceProvider Class (MSDN or dotnetperls)
It implements IDisposable.
using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
{
byte[] randomNumber = new byte[4];//4 for int32
rng.GetBytes(randomNumber);
int value = BitConverter.ToInt32(randomNumber, 0);
}