JS随机数某个范围的浮点

function randomTest() {
var result = fullClose(0, 1.5);
console.log("随机数:" + Math.round(result * 100) / 100);
}

function fullClose(n, m) {
var result = Math.random() * (m + 1 - n) + n;
while (result > m) {
result = Math.random() * (m + 1 - n) + n;
}
return result;
}
posted @ 2020-06-09 21:48  Birdgeduan  阅读(575)  评论(0编辑  收藏  举报