Math.random()方法
如上面标题,Math.random()就是小程序获取随机数的方法
var i = Math.random()
//i的取值范围为[0,1)的小数,[]是包含等于 (不好含等于
i = Math.random() * 10
//i的取值范围为[0,10)的小数
i = Math.random() * 10 + 10
//i的取值范围为[10,20)的小数
toFixed(0)四舍五入取整
注意:上面获取的都是小数,接下来取整
var i = (Math.random()).toFixed(0)
//i的取值范围为[0,1)的小数,[]是包含等于 (不好含等于
i = (Math.random() * 10).toFixed(0)
//i的取值范围为[0,10)的小数
i = (Math.random() * 10 + 10).toFixed(0)
//i的取值范围为[10,20)的小数
代码代写(实验报告、论文、小程序制作)服务请加微信:ppz2759
关注公众号回复:“小程序”获取2000套小程序源码