如何在 javascript 中返回一个随机数,每次代码重新运行时该随机数始终大于前一个随机数。例如,当代码第一次运行时,它返回 1000,第二次运行时,它返回 1300。
条件:该数字必须始终是整数。
最佳答案
function randomFunction() {
var x = 0
return function() {
x = x + Math.round( Math.random() * 100 )
return x
}
}
var nextRandom = randomFunction()
nextRandom() // => 51
nextRandom() // => 127
nextRandom() // => 203
关于javascript - 如何在javascript中返回一个始终大于前一个数字的随机数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32867068/