我担心 arc4random 背叛了我
我有一段代码可以从 0 到 1 之间随机生成一个数字。我发现数字 1 出现的次数比数字 0 出现的次数要多得多,我认为这在统计上是可能的。
这是我的代码:
int shipNumber = arc4random() % 2;
这段代码应该工作吗?我是不是要疯了?
I have code that pics a random number from 0 to 1. I am seeing that the number 1 is coming up far more times then the number 0 then I would think to be statistically possible.
This is my code:
int shipNumber = arc4random() % 2;
Should this code work? Am I just going crazy?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该代码应该可以工作。
我怀疑你所看到的确实是随机的(或者至少是足够随机的),并且你的大脑正在试图寻找模式。 (每个人的大脑都试图在各处寻找模式。这就是你阅读这篇文章的方式。问题是随机性中没有模式[这几乎是定义]可供你的大脑抓住,所以它发明了一些模式。)
如果你如果确实想检查输出的随机性,您需要进行某种统计分析。
That code should work.
What I suspect you're seeing is truly random (or, at least, sufficiently random) and your brain is trying to find patterns. (Everybody's brain tries to find patterns everywhere. That's how you're reading this. The issue is there are no patterns in randomness [that being pretty much the definition] for your brain to latch on to, so it invents some.)
If you really want to check your output for randomness, you'll need to do a statistical analysis of some kind or other.
您可能会看到模偏差。
You might be seeing modulo bias.