RNGCryptoServiceProvider故障卡方检验的大的随机数随机数、故障、RNGCryptoServiceProvider

2023-09-11 22:57:08 作者:独白了吗

是否有任何人知道为什么RNGCryptoServiceProvider试图获得更大的数字,然后3亿失败时,卡方检验。

Does any one know why the RNGCryptoServiceProvider fail chi-square test when trying to get numbers bigger then 300,000,000.

我试图让范围内的0-1,000,000,000和我收到故障卡方检验结果的随机数,在范围0-300,000,000的数字比其它数字出现了。

I tried to get random number in the range 0-1,000,000,000 and the result that I received fail chi-square test, the numbers in the range 0-300,000,000 appeared more than the other numbers.

最后,我合并的大数字形式更小的数字(0-99 * 100M + 0-99,999,999)和卡方检验合格。

eventually i combined the big number form to smaller numbers (0-99 *100M + 0-99,999,999) and the chi-square test pass.

谁能解释这种异常大的数字?

can anyone explain this anomaly in big numbers?

我用下面的code得到的数字

I used the following code to get the numbers

    [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([计数],[预计])

Take the Result.txt file and copy the content to an excel. make it a table and add 2 columns 1 is the expected result with the value 100000 and the second one is the Chi-square test the value is "=CHISQ.TEST([count],[[expected ]])"

在卡方检验值小于0.1,我们有一个问题。

when the value of the chi-square test is less than 0.1 we have a problem.

推荐答案

最有可能的问题是,你推出一个偏见,当您使用剩余技术。请参见的余技术是多少偏见出台? 一个解释。

Most likely the problem is that you're introducing a bias when you use the remainder technique. See How much bias is introduced by the remainder technique? for an explanation.