.net 随机数

system.Random类生成的随机数是伪随机,因此使用system.Security.Cryptography.RNGCryptoServiceProvider的类

 1  static int GetRandomSeed()
 2     {
 3         byte[] bytes = new byte[4];
 4         System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
 5         rng.GetBytes(bytes);
 6         return BitConverter.ToInt32(bytes, 0);
 7     }
 8 
 9     static int GetNumber()
10     {
11         return Math.Abs(GetRandomSeed());
12     }

猜你喜欢

转载自www.cnblogs.com/cg-931210/p/9263162.html