生成真随机数
使用RNGCryptoServiceProvider生成真随机数的方法:
1 //获取len位真随机数字(真随机数) 2 public static string GetRealRandomNum(int len) 3 { 4 var sb = new StringBuilder(); 5 byte[] data = new byte[len]; 6 using (var provider = new RNGCryptoServiceProvider()) 7 { 8 provider.GetBytes(data); 9 foreach (byte item in data) 10 { 11 string temp = (item % 10).ToString(); 12 sb.Append(temp); 13 } 14 } 15 return sb.ToString(); 16 }