例如取5000到8000之间的随机数:
a=Math.round(Math.random()*(8000-5000)+5000);
<script> //获取 0~1.0 之间的随机数:结果格式: 0.08497309126586194 a=Math.random(); console.log(a); //随机获取 0~10 之间的一个整数: a=Math.round(Math.random()*10); console.log(a); /*取随机指定范围内的数字 例如:123-999*/ a=Math.round(Math.random()*(999-123)+123); console.log(a); /*取随机指定范围内的数字 例如 10000-50000*/ function get_rand(最小,最大){ return Math.round(Math.random()*(最大-最小)+最小); } a=get_rand(10000,50000); console.log(a); </script>