微信小程序生成随机数 0或者1 js代码

时间:2019-10-19 19:04:19   收藏:0   阅读:154
Math.floor(Math.random() + 0.5)

  

Math.random()的取值范围是:

0<=Math.random()<1  随机小数

 

Math.floor(X) =X的整数位
例如
Math.floor(6.999)  ===  6
Math.floor(39.001)   ===  39
Math.floor(8)   ===  8

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!