随身笔记
随身笔记

Math.floor(Math.random() * 7 + 1);是什么意思?

Math.random()默认直接调用是随机获取0和1之间小数;

Math.random() * 7随机获取0和7之间小数;

Math.random() * 7 + 1随机获取0和8之间小数;

Math.floor()获取括号里面的整数;

Math.floor(Math.random() * 7 + 1)随机获取0和8之间整数;

没有标签
首页      前端资源      JavaScript笔记      Math.floor(Math.random() * 7 + 1);是什么意思?

随身笔记

Math.floor(Math.random() * 7 + 1);是什么意思?
Math.random()默认直接调用是随机获取0和1之间小数; Math.random() * 7随机获取0和7之间小数; Math.random() * 7 + 1随机获取0和8之间小数; Math.floor()获取括号里面的整数…
扫描二维码继续阅读
2013-12-31