我知道有几个问题,但我很难找到如何使用Math.random获取两个高整数之间的随机数?
所以,例如,在50到80之间.我认为这会起作用......
'left': Math.floor((Math.random() * 80) + 50) + '%'
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
kay*_*yz1 16
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Run Code Online (Sandbox Code Playgroud)
Kar*_*non 13
你需要知道随机的范围.
在50到80之间,范围是30(80 - 50 = 30),然后你加1.
因此,随机看起来像这样:
Math.floor(Math.random() * 31) + 50
Run Code Online (Sandbox Code Playgroud)