WEIGHTED_RANDOM
Weighted random table calculators.
- SharedWEIGHTED_RANDOM:Add(data, weight) → WEIGHTED_RANDOMSource ☍
-
Add a new entry to the weighted table.
Parameters
- dataanyThe data to insert. If a table, the .weight field is used as the weight.
- weightnumber?The manual override weight value, or nil to use the entry's .weight or default to 1.
Returns
- WEIGHTED_RANDOMThe weighted table (for chaining).
- SharedWEIGHTED_RANDOM:New() → WEIGHTED_RANDOMSource ☍
-
Create a new weighted random table instance.
Returns
- WEIGHTED_RANDOMThe newly created instance.
- SharedWEIGHTED_RANDOM:Random() → anySource ☍
-
Pull out a random value from the table, respecting the weights of the table.
Returns
- anyThe selected value, or nil if the table is empty.
- SharedWEIGHTED_RANDOMSource ☍
-
A small helper for selecting elements at random where each element has an associated weight. Supports adding arbitrary data entries with optional weight overrides and sampling respecting weights.
- SharedWEIGHTED_RANDOMSource ☍
-
A small helper for selecting elements at random where each element has an associated weight. Supports adding arbitrary data entries with optional weight overrides and sampling respecting weights.