软件编程
位置:首页>> 软件编程>> C#编程>> C# 生成随机数的代码

C# 生成随机数的代码

作者:hebedich  发布时间:2021-06-16 06:05:43 

标签: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;
}
0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com