C# 生成隨機數(shù)的代碼
更新時間:2015年03月23日 16:18:20 投稿:hebedich
這篇文章主要介紹了C# 生成隨機數(shù)的代碼的相關(guān)資料,非常的簡單實用,需要的朋友可以參考下
/// 構(gòu)造隨機數(shù) 種子
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);
}
/// 生成隨機 數(shù)
static int rnd()
{
Random ran = new Random(GetRandomSeed());
int cnt = ran.Next(0,59);
return cnt;
}
以上就是本文的全部內(nèi)容了,希望大家能夠喜歡,能夠?qū)Υ蠹覍W(xué)習(xí)C#有所幫助。
相關(guān)文章
C#實現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法
這篇文章主要介紹了C#實現(xiàn)為一張大尺寸圖片創(chuàng)建縮略圖的方法,涉及C#創(chuàng)建縮略圖的相關(guān)圖片操作技巧,需要的朋友可以參考下2015-06-06
C#實現(xiàn)利用Windows API讀寫INI文件的方法
這篇文章主要介紹了C#實現(xiàn)利用Windows API讀寫INI文件的方法,涉及C#針對ini文件的創(chuàng)建、讀取及寫入等操作技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07

