Weighted Bag
Overview
Weighted bags are distributions with a limited count of each item, as well as an integer weight for each item. Each item's probability equals its weight divided by the total weight of all items. Each item's probability does not change until the item's count reaches 0.
Example 1
Suppose we have a weighted bag of colored balls:
Distribution A (Weighted Bag) | |||
---|---|---|---|
Color | Count | Weight | Probability |
Red | 3 | 100 | 33% (100 / 300) |
Blue | 2 | 100 | 33% (100 / 300) |
Green | 5 | 100 | 33% (100 / 300) |
Suppose we sample Red from the bag. It becomes:
Distribution A (After Sampling Red) | |||
---|---|---|---|
Color | Count | Weight | Probability |
Red | 2 | 100 | 33% (100 / 300) |
Blue | 2 | 100 | 33% (100 / 300) |
Green | 5 | 100 | 33% (100 / 300) |
Although red's count changed, its probability is still the same. Suppose we sampled Red twice more:
Distribution A (After Sampling Red x2) | |||
---|---|---|---|
Color | Count | Weight | Probability |
Red | 0 | 100 | 0% (Ineligible) |
Blue | 2 | 100 | 50% (100 / 200) |
Green | 5 | 100 | 50% (100 / 200) |
Now red's count has become 0 and it is ineligible.
Example 2
Items are ineligible when Count = 0 OR Weight = 0.
Distribution B (Weighted Bag) | |||
---|---|---|---|
Color | Count | Weight | Probability |
Red | 0 | 100 | 0% (Ineligible) |
Blue | 2 | 0 | 0% (Ineligible) |
Green | 5 | 100 | 100% (100 / 100) |
Advanced
Eligibility
Count > 0 and Weight > 0.