用js如何得到3-7的随机数用Mathround取整
可以使用以下代码得到3-7的随机数:
var randomNum = Math.floor(Math.random() * 5) + 3;
其中,Math.random()函数会返回一个0到1之间的随机小数,乘以5后得到0到5之间的随机数,再加上3,最终得到3到7之间的随机整数。使用Math.floor()函数取整可以保证得到的是整数。
原文地址: https://www.cveoy.top/t/topic/bhVN 著作权归作者所有。请勿转载和采集!