• Selects a random value from a weighted set of items.

    Parameters

    • set: WeightedItem[]

      An array of items with associated weights.

    Returns number

    The selected item's value.

    If the input array is empty or if weights sum to 0.

    const items: WeightedItem[] = [
    { value: 1, weight: 5 },
    { value: 2, weight: 3 },
    { value: 3, weight: 2 },
    ];
    const result = weightedPick(items); // Randomly picks based on weights