//這樣產生0 ~ 100的強隨機數(含100)
int max = 100;
int rnd = int.MinValue;
decimal _base = (decimal)long.MaxValue;
byte[] rndSeries = new byte[8];
System.Security.Cryptography.RNGCryptoServiceProvider rng
= new System.Security.Cryptography.RNGCryptoServiceProvider();
rng.GetBytes(rndSeries);
//不含100需去掉+1
rnd = (int)(Math.Abs(BitConverter.ToInt64(rndSeries, 0)) / _base * (max+1));
//這個rnd就是你要的隨機數,
//但是要注意別扔到循環裡去,實例化RNG對象可是很消耗資源的