function weightRandom(randomConfig) {
//var randomConfig = [{id:11,w:3},{id:12,w:1}];
//SpawnEventID, Weight
var randomList = [];
for (var i in randomConfig) {
for (var j = 0; j < randomConfig[i].w; j++) {
randomList.push(randomConfig[i].id);
//The list above is supposed to be like [11,11,11,12]
//So for the god's sake the value of w cannot be too large
}
}
var randomValue = randomList[Math.floor(Math.random() * randomList.length)];
return randomValue;
};
function weightRandom(randomConfig) {
//var randomConfig = [{id:11,w:3},{id:12,w:1}];
//SpawnEventID, Weight
var randomList = [];
for (var i in randomConfig) {
for (var j = 0; j < randomConfig[i].w; j++) {
randomList.push(randomConfig[i].id);
//The list above is supposed to be like [11,11,11,12]
//So for the god's sake the value of w cannot be too large
}
}
var randomValue = randomList[Math.floor(Math.random() * randomList.length)];
return randomValue;
};