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

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

posted @ 2019-10-19 18:42  在学习编程的lsy呀  阅读(3257)  评论(0编辑  收藏  举报