Re: 64 bit random numbers
From: Michael Giagnocavo [MVP] (mggUNSPAM_at_Atrevido.net)
Date: Tue, 21 Oct 2003 14:07:34 -0600
You can use the System.Security.Cryptography.RNGCryptoServiceProvider to get
a random number generator. Then you should be able to use GetBytes to fill
a byte array. From there, you can use System.BitConverter to change those
bytes into UInt64s.
"george r smith" <email@example.com> wrote in message
> I am trying to compute a an array of four 64 bit random numbers
> but I am not having any luck. Following is my code. The problem is in
> the line aUInt64 = UInt64.Parse(aString);
> I thought that since a byte is 8 bits that an array of eight Bytes would
> give me a 64 bit number but since some of the strings are comming
> back with 22 characters the program blows up because the number
> is too large.
> The docs say that UInt64 (same as ulong) cannot exceed
> 18,446,744,073,709,551,615 so I think that is my problem.
> Can some one show me how to compute this array of 64 bit
> random numbers. Am I using the wrong library.
> thanks much
> static void Main(string args)
> byte random = new Byte;
> System.UInt64 aUInt64 = 0;
> int aLength;
> RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
> for (int count = 0; count < 4; count++)
> String aString = "";
> for (int i = 0; i < 8; i++)
> aString = aString + random[i].ToString();
> aLength = aString.Length; // for debug just want to see
> aUInt64 = UInt64.Parse(aString);