Random.Next()
only generates 31 bits of true randomness:
A 32-bit signed integer greater than or equal to zero and less than MaxValue.
Since the result is always positive, the most significant bit is always 0.
You could generate two int
s and combine them to get a number with 62 bits of randomness:
data = ((ulong)rnd.Next() << 32) + rnd.Next();
If you want 64 bits of randomness, another method is to generate 8 random bytes using GetBytes
:
byte[] buffer = new byte[8];
rnd.NextBytes(buffer);
data = BitConverter.ToUInt64(buffer, 0);