我如何解释顽固分子的结果以获得伟大的正义 [英] How do I interpret the results from dieharder for great justice

查看:34
本文介绍了我如何解释顽固分子的结果以获得伟大的正义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个关于 SO 问题的问题;尽管根据定义它是 sp,但我不认为它属于元数据,但如果有人认为它应该用于数学、交叉验证等,请告诉我.

This is a question about an SO question; I don't think it belongs in meta despite being sp by definition, but if someone feels it should go to math, cross-validated, etc., please let me know.

背景:@ForceBru 问这个问题关于如何使用 rand() 生成 64 位随机数.@nwellnhof 提供了一个被接受的答案,该答案基本上采用 5 个随机数的低 15 位(因为 MAXRAND 显然只能保证至少在某些编译器上为 15 位)并将它们粘合在一起,然后删除前 11 位(15*5-64=11).@NikBougalis 发表评论说,虽然这看起来合理,但它不会通过随机数的许多统计测试.@Foon(我)要求引用或测试失败的例子.@NikBougalis 回答了一个没有阐明我的答案;@DavidSwartz 建议针对顽固分子运行它.

Background: @ForceBru asked this question about how to generate a 64 bit random number using rand(). @nwellnhof provided an answer that was accepted that basically takes the low 15 bits of 5 random numbers (because MAXRAND is apparently only guaranteed to be 15bits on at least some compilers) and glues them together and then drops the first 11 bits (15*5-64=11). @NikBougalis made a comment that while this seems reasonable, it won't pass many statistical tests of randomnes. @Foon (me) asked for a citation or an example of a test that it would fail. @NikBougalis replied with an answer that didn't elucidate me; @DavidSwartz suggested running it against dieharder.

所以,我更加顽固.我针对有问题的算法运行了它

So, I ran dieharder. I ran it against the algorithm in question

unsigned long long llrand() {
    unsigned long long r = 0;

    for (int i = 0; i < 5; ++i) {
        r = (r << 15) | (rand() & 0x7FFF);
    }

    return r & 0xFFFFFFFFFFFFFFFFULL;
}

为了比较,我当时也只针对 rand() 和 8 位的 rand() 运行它.

For comparison, I also ran it against just rand() and just 8bits of rand() at at time.

void rand_test()
{
int x;
srand(1);
  while(1)
    {
      x = rand();
      fwrite(&x,sizeof(x),1,stdout);
    }

void rand_byte_test()
{
  srand(1);
  while(1)
    {
      x = rand();
      c = x % 256;
      fwrite(&c,sizeof(c),1,stdout);
    }
}

所讨论的算法返回了两个测试,显示 rgb_lagged_sum 对于 ntuple=28 和 sts_serials 之一对于 ntuple=8 的弱点.

The algorithm under question came back with two tests showing weakenesses for rgb_lagged_sum for ntuple=28 and one of the sts_serials for ntuple=8.

仅使用 rand() 在许多测试中都失败了,大概是因为我取了一个具有 15 位随机性的数字并将其作为 32 位随机性传递.

The just using rand() failed horribly on many tests, presumably because I'm taking a number that has 15 bits of randomness and passing it off as 32 bits of randomness.

一次使用 rand() 的低 8 位对于带有 ntuple 2 的 rgb_lagged_sum 来说很弱,并且(编辑)失败的 dab_monobit,带有元组 12

The using the low 8 bits of rand() at a time came back as weak for rgb_lagged_sum with ntuple 2, and (edit) failed dab_monobit, with tuple 12

我的问题是:

  1. 我是否正确地解释了 8 位随机的结果,即考虑到其中一项测试(标记为好";根据记录,对于标记为嫌疑人"),来得一样弱,一则失败,应该怀疑 rand() 的随机性.
  2. 我是否正确地解释了被测算法的结果(即这也应该被轻微怀疑)
  3. 鉴于对返回为弱的测试的描述(例如,对于 sts_serial,查看特定大小的位模式的分布是否有效),我是否应该能够确定偏差可能是什么
  4. 如果是 3,因为我不是,有人可以指出我应该看到什么吗?

理解 rand() 并不能保证很好.此外,我试图考虑哪些值不太可能,并推测可能是零、最大值或重复数字......但是进行了 1000000000 次尝试的测试,该比率非常接近每 2 个中 1 个的预期值^15 次(例如,在 1000000000 次运行中,我们看到 30512 个零、30444 个最大值和 30301 个重复,并且 bc 说 30512 * 2^15 是 999817216;其他运行具有相似的比率,包括最大值和/或重复大于零的情况.

understood that rand() isn't guaranteed to be great. Also, I tried to think what values would be less likely, and surmised zero, maxvalue, or repeated numbers might be... but doing a test of 1000000000 tries, the ratio is very near the expected value of 1 out of every 2^15 times (e.g., in 1000000000 runs, we saw 30512 zeros, 30444 max, and 30301 repeats, and bc says that 30512 * 2^15 is 999817216; other runs had similar ratios including cases where max and/or repeat was larger than zeros.

推荐答案

当你运行顽固时,你真正需要关注的列是 p 值列.

When you run dieharder the column you really need to watch is the p-value column.

p 值列本质上说:这是真实随机数可能产生此结果的概率."您希望它在 0 和 1 之间均匀分布.

The p-value column essentially says: "This is the probability that real random numbers could have produced this result." You want it to be uniformly distributed between 0 and 1.

您还需要在可疑案例上多次运行它.例如,如果您有一列的 p 值为(例如).03,那么如果您重新运行它,您仍然有 0.03(而不是更高的值),那么您可以高度自信地确定您的随机数数字生成器在该测试中表现不佳,这不仅仅是 3% 的侥幸.但是,如果您获得高值,那么您可能正在寻找统计上的侥幸.但它是双向的.

You'll also want to run it multiple times on suspect cases. For instance, if you have a column with a p-value of (for instance) .03 then if you re-run it, you still have .03 (rather than some higher value) then you can have a high confidence that your random number generator performs poorly on that test and it's not just a 3% fluke. However, if you get a high value, then you're probably looking at a statistical fluke. But it cuts both ways.

最终,了解有关随机或伪随机过程的事实是很困难的.但有了顽固分子,你对很多事情都有大概的了解.

Ultimately, knowing facts about random or pseudorandom processes is difficult. But armed with dieharder you have approximate knowledge of many things.

这篇关于我如何解释顽固分子的结果以获得伟大的正义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆