使用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)
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!