rand() 的奇怪行为 [英] Strange behaviour with rand()

查看:59
本文介绍了rand() 的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么条件 rand() % 3 大约每 3 次为真?rand 真的是随机的,不是吗?

Why condition rand() % 3 is true approximatelу EVERY 3 time ? rand is REALY random isn't it ?

推荐答案

当然,您意识到即使是一枚公平的硬币也可以让您连续十次正面朝上.有一个概率可以分配给该组合.

You realize, of course, that even a fair coin can give you ten heads in a row. There's a probability that can be assigned to that combination.

一枚公平的硬币会在多次试验中产生一半正面和一半反面,但不能保证在较短的时间内达到 50/50.

A fair coin will give half heads and half tails over many trials, but it's not guaranteed to be 50/50 over a shorter run.

您自己对物理世界的体验告诉您,您的结论是错误的.rand() 也是如此.

Your own experience of the physical world tells you that your conclusion is incorrect. Same is true for rand().

这篇关于rand() 的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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