NineAI 2.4.2

This commit is contained in:
vastxie
2024-01-17 09:22:28 +08:00
commit bdc48207fc
636 changed files with 41864 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectKeyWithWeight = void 0;
function selectKeyWithWeight(data) {
if (data.length === 0)
return undefined;
const totalWeight = data.reduce((sum, item) => sum + item.weight, 0);
let randomWeight = Math.random() * totalWeight;
for (const item of data) {
randomWeight -= item.weight;
if (randomWeight < 0) {
return item;
}
}
return data[data.length - 1];
}
exports.selectKeyWithWeight = selectKeyWithWeight;