码迷,mamicode.com
首页 > Windows程序 > 详细

c# 解决Randoms伪随机重复问题

时间:2018-10-13 13:41:14      阅读:188      评论:0      收藏:0      [点我收藏+]

标签:bytes   code   问题   convert   cep   void   oms   new   color   

/// <summary>
/// 解决伪随机问题
/// </summary>
public static void Random()
{
int t = 0;
for (int i = 0; i < 10; i++)
{
byte[] bytes = new byte[4];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(bytes);
t = BitConverter.ToInt32(bytes, 0);
Random rnd = new Random(t);
Console.WriteLine(rnd.Next(0, 10));
}
}

 

c# 解决Randoms伪随机重复问题

标签:bytes   code   问题   convert   cep   void   oms   new   color   

原文地址:https://www.cnblogs.com/yuanzijian-ruiec/p/9782594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!