C# 解决Random伪随机同一时间点随机值重复的问题

方法1:

Random rand = new Random(Guid.NewGuid().GetHashCode());
int randomInt = rand.Next(1, 10);

 

方法2:

byte[] bytes = new byte[4];
System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(bytes);
int t = BitConverter.ToInt32(bytes, 0);
Random rnd = new Random(t);
int randomInt = rand.Next(1,10)

  

  

C# 解决Random伪随机同一时间点随机值重复的问题

上一篇:C#抽象类和接口的区别


下一篇:前后端分离开发vue+Elementyui+abpcorewebapi商城管理系统(二)前端项目初始化