C#生成隨機數(shù)的三種方法
當前位置:點晴教程→知識管理交流
→『 技術文檔交流 』
Random rd = new Random(); int i = rd.Next(); for (int i = 0; i < 10; i++) { Random rd = new Random(); //無參即為使用系統(tǒng)時鐘為種子 Console.WriteLine(rd.Next().ToString()); } Random random = new Random(); for (int i = 0; i < 5; i++) { Console.WriteLine(random.Next()); } Console.WriteLine(Guid.NewGuid().ToString());
RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider(); byte[] byteCsp = new byte[10]; csp.GetBytes(byteCsp); Console.WriteLine(BitConverter.ToString(byteCsp)); for (int i = 0; i < 10; i++) { RNGCryptoServiceProvider csp = new RNGCryptoServiceProvider(); byte[] byteCsp = new byte[10]; csp.GetBytes(byteCsp); Console.WriteLine(BitConverter.ToString(byteCsp)); } 該文章在 2024/1/1 22:58:50 編輯過 |
關鍵字查詢
相關文章
正在查詢... |