Math.random()
Math.random() 返回 0(包括) 至 1(不包括) 之间的随机数:
实例
Math.random(); // 返回随机数
亲自试一试
Math.random() 总是返回小于 1 的数。
JavaScript 随机整数
Math.random() 与 Math.floor() 一起使用用于返回随机整数。
实例
Math.floor(Math.random() * 10); // 返回 0 至 9 之间的数
亲自试一试
实例
Math.floor(Math.random() * 11); // 返回 0 至 10 之间的数