有谁知道为什么RNGCryptoServiceProvider在试图得到大于3亿,000,000的数字时不通过卡方检验。
我试图得到0-1,000,000,000,000范围内的随机数,结果我得到的结果是不合格的卡方检验,在0-300,000,000范围内的数字比其他数字多。
最后,我将大数字形式与较小的数字(0-99 *100 m+ 0-99,999,999)和卡方测试通行证结合在一起。
有人能用大量的数字来解释这种反常现象吗?
我使用了下面的代码来获取数字
[Timeout(TestTimeout.Infinite), TestMethod]
public void TestMethodStatistic()
{
Dictionary<long, long> appearances = new Dictionary<long, long>();
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(计数,[预期])”。
当卡方检验的值小于0.1时,我们就有问题了。
发布于 2014-01-02 17:26:22
最有可能的问题是,当您使用剩余技术时,您正在引入一种偏见。有关解释,请参见余数技术引入了多少偏差?。
https://stackoverflow.com/questions/20879023
复制相似问题