如何计算介于0和1之间的随机数?当我使用Math.random()时,它返回0-0.9999999
我没有找到任何解决方案。
编辑:我认为可能是这样的:
const precision = 1000
let c = 0
let min = 2
let max = -2
while(c !== 20000){
c++;
let r = (Math.round(Math.random()*precision)/precision)/0.9999999999999;
r = Math.round(r*precision)/precision
max = Math.max(r, max)
min = Math.min(r, min)
}
console.log('max:', max, 'min:', min)发布于 2017-01-13 17:03:09
https://stackoverflow.com/questions/41630717
复制相似问题