c# 解决Randoms伪随机重复问题
程序员文章站
2022-05-12 13:01:01
/// /// 解决伪随机问题 /// public static void Random() { int t = 0; for (int i = 0; i < 10; i++) { byte[] bytes = new byte[4]; System.Security.Cryptography.R... ......
/// <summary> /// 解决伪随机问题 /// </summary> public static void random() { int t = 0; for (int i = 0; i < 10; i++) { byte[] bytes = new byte[4]; system.security.cryptography.rngcryptoserviceprovider rng = new system.security.cryptography.rngcryptoserviceprovider(); rng.getbytes(bytes); t = bitconverter.toint32(bytes, 0); random rnd = new random(t); console.writeline(rnd.next(0, 10)); } }