生成随机数(高精度,不重复)

来源:互联网 发布:it technician 编辑:程序博客网 时间:2024/06/05 11:11
for(inti = 0; i < 10; i++)
{
    byte[] bytes = newbyte[4];
    //使用加密服务提供程序 (CSP) 提供的实现来实现加密随机数生成器 (RNG)。
    System.Security.Cryptography.RNGCryptoServiceProvider rng = newSystem.Security.Cryptography.RNGCryptoServiceProvider();
    //用经过加密的强随机值序列填充字节数组。
    rng.GetBytes(bytes);
    //将字节转换成32整数
    intn = BitConverter.ToInt32(bytes, 0);
    Console.Write(newRandom(n).Next(1,11)+" ");
 }