一个简单的函数,产生随机整数: function rnd(start, end){ return Math.floor(Math.random() * (end - start) + start); } 如rnd(10, 100)将产生10~100之间的整数,其中Math.random()产生0-1的随机数,乘以(100-10)将得到0~90的数,再加上10得到10~100的数,然后用Math.floor对该结果取整。 相关文章: 2021-10-18 2021-12-24 2022-12-23 2021-11-03 2021-10-24 2022-12-23 2022-03-03