C#生成随机数的三种方法
当前位置:点晴教程→知识管理交流
→『 技术文档交流 』
Random rd = new Random(); int i = rd.Next(); for (int i = 0; i < 10; i++) { Random rd = new Random(); //无参即为使用系统时钟为种子 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 编辑过 |
关键字查询
相关文章
正在查询... |