使用Math产生两数之间的随机数
时间:2021-06-17 16:44:03
收藏:0
阅读:0
两数之间随机数,可以用两数之间的最小数(min),最大数(max)
一·、(最大数max-最小数min)+最小数(min)
Math.ceil(Math.random()*(max-min)+min)
二、(最小数min-最大数max)+最大数(max)
Math.ceil(Math.random()*(min-max)+max)
注意:如果使用向下取值(floor)需要在随机数+1

评论(0)