当前位置: 首页 > 新闻动态 > 软件编程

C# 生成随机数的代码

作者:用户投稿 浏览: 发布日期:2026-01-16
[导读]:这篇文章主要介绍了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#有所帮助。

免责声明:转载请注明出处:http://m.jing-feng.com.cn/news/450729.html

扫一扫高效沟通

多一份参考总有益处

免费领取网站策划SEO优化策划方案

请填写下方表单,我们会尽快与您联系
感谢您的咨询,我们会尽快给您回复!