方法1:
Random rand = new Random(Guid.NewGuid().GetHashCode()); int randomInt = rand.Next(1, 10);
方法2:
byte[] bytes = new byte[4]; System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider(); rng.GetBytes(bytes); int t = BitConverter.ToInt32(bytes, 0); Random rnd = new Random(t); int randomInt = rand.Next(1,10)