cerceis-lib
Version:
Contains list of quality of life functions that is written in TypeScript and es6
21 lines (20 loc) • 566 B
JavaScript
export class Gacha {
constructor() {
this.entries = [];
this.accumulatedWeight = 0.0;
}
addEntries(item, weight) {
this.accumulatedWeight += weight;
this.entries.push({
obj: item,
accumulatedWeight: this.accumulatedWeight
});
}
getRandom() {
var _a;
const r = Math.random() * this.accumulatedWeight;
return (_a = this.entries.find((entry) => {
return entry.accumulatedWeight >= r;
})) === null || _a === void 0 ? void 0 : _a.obj;
}
}