Optionally merge with an existing WeightedList.
Optionallist: WeightedList<T>An existing WeightedList to merge with, if provided.
Remove all items from the list and reset it.
Returns the total weight of all items inside the list.
The total weight of all items.
Returns and removes a random item from the list based on its weight.
The item and its weight, or undefined if the list is empty.
Returns the probability of a specific item inside the list based on its weight.
The index of the item.
The probability of the item, or undefined if the index is invalid.
Add one or more objects with their associated weights.
One or more objects with their weights to add to the list.
Get a random object from the list based on its weight. The higher the weight, the more likely it will be chosen.
A random object from the list or undefined if the list is empty.
Returns a string representation of the WeightedList.
A string summarizing the list, including length, total weight, and item details.
Returns a list of all objects and their associated weights.
An array of objects and their weights.
A WeightedList can be used as an easy way to calculate probabilities based on weights, relative to other items inside the list.