- using System.Security.Cryptographt;
- using System;
-
- byte[] randomBytes = new byte[4];
- RNGCryptoServiceProvider rngCrypto =
- new RNGCryptoServiceProvider();
- rngCrypto.GetBytes(randomBytes);
-
- int rngNum = BitConverter.ToInt32(randomBytes, 0) % n;//此为随机数
N是范围,用U3D的random太容易出相同数了;