理解math.floor(math.random() * (max - min + 1)) + min
Math.random()函数是返回一个浮点数, 伪随机数在范围从0到小于1;
Math.floor()返回小于或等于一个给定数字的最大整数。
console.log(Math.random());
console.log(Math.floor(Math.random()));
我们可以通过查看网页控制台以下结果,console.log(Math.floor(Math.random()))我们只能取到唯一整数0,而1是取不到的。
如何取到1?我们可以试着将Math.rando...
原创
2021-09-10 17:50:05 ·
563 阅读 ·
0 评论