/**
 * Get a random item from a weighted pool
 * @param {{weight: number, any}[]} pool 
 */
export function getItemFromWeightedPool(pool, rolls = 1) {
    const totalWeight = pool.reduce((acc, item) => acc + item.weight, 0);
    const rnd = Math.random() * totalWeight;

    // Iterate through the pool and pick the item based on cumulative weight
    let cumulativeWeight = 0;
    const rolledItems = [];
    for (let i = 0; i < rolls; i++) {
        for (const item of pool) {
            cumulativeWeight += item.weight;
            if (rnd <= cumulativeWeight) {
                rolledItems.push(item)
            }
        }
    }

    return rolledItems;
}