var flip = Math.floor(Math.random() * (1 - 0 + 1)) + 0;?

var flip = Math.floor(Math.random() * (1 - 0 + 1)) + 0;?

本文关键字:Math floor flip random var      更新时间:2023-09-26

我发现了一些代码片段,我不确定这是什么意思:

var flip = Math.floor(Math.random() * (1 - 0 + 1)) + 0;

Math.floor(Math.random() * (max - min + 1)) + min

我还在熟悉Javascript…谁能给我一份简明版的读者文摘?

Math.floor()向下四舍五入到最接近的整数

例如:如果你有2.7,它将四舍五入到2

Math.random()返回0到1之间的随机数

例如:.693