RNGCryptoServiceProvider对大型随机数进行卡方检验失败

有没有人知道为什么RNGCryptoServiceProvider在试图获得超过300,000,000的数字时失败进行卡方检验。

我试图得到0-1,000,000,000范围内的随机数,结果我得到了卡方检验失败,0-300,000,000范围内的数字显得比其他数字更多。

最终我将大数字forms与较小的数字(0-99 * 100M + 0-99,999,999)和卡方测试通过相结合。

任何人都可以大量解释这个exception现象吗?

我使用以下代码来获取数字

[Timeout(TestTimeout.Infinite), TestMethod] public void TestMethodStatistic() { Dictionary appearances = new Dictionary(); UInt64 tenBillion = 10000000000; for (UInt64 i = 0; i < 10000000; i++) { UInt64 random = GetSIngleRandomNumberInternal() % tenBillion; UInt64 bucket = random /10000000; if (!appearances.ContainsKey(Convert.ToInt64(bucket))) { appearances.Add(Convert.ToInt64(bucket), 0); } appearances[Convert.ToInt64(bucket)]++; } string results = "\nBucket Id\tcount\n"; foreach (var appearance in appearances) { results += appearance.Key+"\t"+ appearance.Value +"\n"; } File.AppendAllText(@"C:\Result.txt",results); } private RNGCryptoServiceProvider rngCsp = new RNGCryptoServiceProvider(); private UInt64 GetSIngleRandomNumberInternal() { byte[] randomNumBytes = new byte[sizeof(UInt64)]; rngCsp.GetBytes(randomNumBytes); return BitConverter.ToUInt64(randomNumBytes, 0); } 

获取Result.txt文件并将内容复制到excel。 使它成为一个表并添加2列1是预期结果,值为100000,第二个是卡方检验,值为“= CHISQ.TEST([count],[[expected]])”

当卡方检验的值小于0.1时,我们遇到了问题。

最有可能的问题是,当您使用余数技术时,您会引入偏差。 请参阅剩余技术引入了多少偏差? 作出解释。