js 中Math.random

{

//n到m随机数 [n,m]

var w=m-n

Math.round(Math.random()*w+n)

}

-------------------------------------------------------------------------

{

// (n,m)

var w=m-n

Math.round(Math.random()*w+n+1)

}

------------------------------------------------------------------------

{

// (n,m]

var w=m-n

Math.floor(Math.random()*w+n) + 1

}

-----------------------------------------------------------------------------

{

// [n,m)

var w=m-n

parseInt(Math.random()*w+n, 10)

}

-----------------------------------------------

猜你喜欢

转载自blog.csdn.net/qq_40708273/article/details/82660720