C# 生成随机数的代码

前端技术 2023/09/04 C#
/// 构造随机数 种子
static int GetRandomSeed()
{
      byte[] bytes = new byte[4];
      System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
      rng.GetBytes(bytes);
      return BitConverter.ToInt32(bytes, 0);
} 
 
/// 生成随机 数
static int rnd() 
{
      
      Random ran = new Random(GetRandomSeed());     
      int cnt = ran.Next(0,59);
      return cnt;
 }

以上就是本文的全部内容了,希望大家能够喜欢,能够对大家学习C#有所帮助。

本文地址:https://www.stayed.cn/item/11119

转载请注明出处。

本站部分内容来源于网络,如侵犯到您的权益,请 联系我

我的博客

人生若只如初见,何事秋风悲画扇。