random 随机数 返回0-1之间的随机数(不包含0 1)
math.random()
(1)返回1-10之间的随机整数
console.log(Math.floor(Math.random()*10+1))
(2)返回0-10之间的随机整数
Math.round(Math.random() * 10)
Math.floor(Math.random()*11)
指定范围的随机数
f1(10,200) 包含10 200
(1) f1(起始,终止) 包含起始和终止
console.log(Math.floor(Math.random() * (20-10+1)) + 10);
Math.floor()
(3)返回指定范围的随机整数
f1(10,200) 包含10和200
(1)f1(起始,终止) 包含起始和终止
console.log(Math.random()*(20-10+1))+10)
Math.floor(Math.random() * (max - min + 1))+min;(重要)
(2) f1(起始,终止) 包含起始和不包含终止
Math.floor(Math.random() * (max - min))+min;
(3) f1(起始,终止) 不包含起始和不包含终止
Math.ceil(Math.random() * (max - min - 1)) + min