// 百分之10几率就是0-10 百分之20几率是10-30,百分之30几率是30-60 百分之40几率是60-100
let gailv = [{ name: "物品1", g: 10 }, { name: "物品2", g: 20 }, { name: "物品3", g: 30 }, { name: "物品4", g: 40 }]
let jishu = gailv[0].g;
let huode = ""
const round = Math.round(Math.random() * 100) //50
for (let index = 0; index < gailv.length; index++) {
if (round < gailv[0].g) {
huode = gailv[0].name
break
}
if (index + 1 != gailv.length) {
if (round > (jishu + gailv[index + 1].g)) {
jishu+=gailv[index+1].g
continue;
}
else {
huode = gailv[index+1].name
break;
}
}
}
console.log(round)
console.log(huode)
05-30
2245

03-19
2599
