积木——“在( )和( )之间取随机数”
-
介绍
随机数就是无法被预测的数。例如,如果一个人说“1、2、3”,接下来你大概会猜下一个数是4。这个数字序列有着明显的模式,所以不是随机的。
然而,如果一个人说“3、1、2”,就没这么容易猜到下一个数是多少。看起来这些数是随机产生的。
积木:“在( )和( )之间取随机数”
利用“运算”类别中的这个积木,你就可以让计算机产生某个范围内的随机数:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/da5de2af-c913-4760-83b9-7d2522781711.png" width="200" style="">
这个积木取2个数作为输入,这2个数确定一个选择范围。例如,如果输入值为1和5,那么我们就有5个数可选:1、2、3、4、5
每次运行这个积木,就会产生一个新数,我们并不知道计算机下次会从这5个数中选择哪一个:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/fc1de2a7-aa61-4a2e-9d10-7a180f336992.gif" width="300" style="">
范围内的所有数被选中的几率相等
注意,在你指定的范围内,所有数被选中的几率相等。比如,如果范围为1至2,然后如果你重复很多次,你得到1的次数和你得到2的次数几乎相等。
若要验证这一点,你可以在1至2范围内取100个随机数,然后看看是不是1和2都大约为50个。
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login