js random

来源:互联网 发布:弗洛伊德算法详解 编辑:程序博客网 时间:2024/04/29 19:40

Math.random()  //范围 [ 0 , 1 )

1、Math.round() // 四舍五入

Math.round(Math.random()*3)   //范围 [ 0 , 4 ]

2、Math.ceil() // 全入

Math.ceil(Math.random()*3)   //范围 [ 1 , 3 ]

3、Math.floor()  // 全舍

Math.floor(Math.random()*4)   //范围 [ 0 , 3 ]


0 0
原创粉丝点击