您如何测试某些东西是随机的?还是“足够随机"? [英] How do you test that something is random? Or "random enough'?

查看:92
本文介绍了您如何测试某些东西是随机的?还是“足够随机"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须从数据库中返回一个随机条目.

I have to return a random entry from my database.

我写了一个函数,由于我在Python中使用random模块,除非我以愚蠢的方式使用它,否则可能是这样.

I wrote a function, and since I'm using the random module in Python, it's probably unless I used it in a stupid way.

现在,我该如何编写一个单元测试来检查此功能是否有效?毕竟,如果它是一个很好的随机值,您永远不会知道.

Now, how can I write a unit test that check that this function works? After all, if it's a good random value, you can never know.

我并不偏执,我的功能并不那么复杂,Python标准库为1000 x 时间足够我的目的.我没有做密码学或重要的事情.我只是想知道是否有办法.

I'm not paranoid, my function is not that complex and the Python standard library is 1000 x time good enough for my purpose. I'm not doing cryptography or something critical. I'm just curious to know if there is a way.

推荐答案

RANDOM上列出了几种统计检验.用于测试随机性的ORG .请参阅链接文章的最后两节.

There are several statistical tests listed on RANDOM.ORG for testing randomness. See the last two sections of the linked article.

此外,如果您可以获得漂亮的测试 John D. Cook 有一整章称为测试随机数生成器.他解释了上面文章中列出的许多统计方法.如果您真的想了解RNG,则本章是一个很好的起点.我已经写过有关该主题的文章,但是John在解释它方面做得更好.

Also, if you can get a copy of Beautiful Testing there's a whole chapter by John D. Cook called Testing a Random Number Generator. He explains a lot of the statistical methods listed in the article above. If you really want to learn about RNGs, that chapter is a really good starting point. I've written about the subject myself, but John does a much better job of explaining it.

这篇关于您如何测试某些东西是随机的?还是“足够随机"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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