Skip to main content

WeightedRandomChooser

Functions

new

WeightedRandomChooser.new() → WeightedRandomChooser<T>

Creates a new weighted random chooser

SetWeight

WeightedRandomChooser:SetWeight(
optionT,
weightnumber | nil
) → ()

Sets the weight for a given option. Setting the weight to nil removes the option.

Remove

WeightedRandomChooser:Remove(optionT) → ()

Removes the option from the chooser. Equivalent of setting the weight to nil

GetWeight

WeightedRandomChooser:GetWeight(optionT) → number | nil

Gets the weight for the option

GetProbability

WeightedRandomChooser:GetProbability(optionT) → number | nil

Gets the percent probability from 0 to 1

Choose

WeightedRandomChooser:Choose(randomRandom) → T

Picks a weighted choise

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Creates a new weighted random chooser",
            "params": [],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "WeightedRandomChooser<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 18,
                "path": "src/randomutils/src/Shared/WeightedRandomChooser.lua"
            }
        },
        {
            "name": "SetWeight",
            "desc": "Sets the weight for a given option. Setting the weight to nil\nremoves the option.",
            "params": [
                {
                    "name": "option",
                    "desc": "",
                    "lua_type": "T"
                },
                {
                    "name": "weight",
                    "desc": "",
                    "lua_type": "number | nil"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 33,
                "path": "src/randomutils/src/Shared/WeightedRandomChooser.lua"
            }
        },
        {
            "name": "Remove",
            "desc": "Removes the option from the chooser. Equivalent of setting the weight to nil",
            "params": [
                {
                    "name": "option",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 50,
                "path": "src/randomutils/src/Shared/WeightedRandomChooser.lua"
            }
        },
        {
            "name": "GetWeight",
            "desc": "Gets the weight for the option",
            "params": [
                {
                    "name": "option",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number | nil"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 60,
                "path": "src/randomutils/src/Shared/WeightedRandomChooser.lua"
            }
        },
        {
            "name": "GetProbability",
            "desc": "Gets the percent probability from 0 to 1",
            "params": [
                {
                    "name": "option",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "number | nil"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 70,
                "path": "src/randomutils/src/Shared/WeightedRandomChooser.lua"
            }
        },
        {
            "name": "Choose",
            "desc": "Picks a weighted choise",
            "params": [
                {
                    "name": "random",
                    "desc": "",
                    "lua_type": "Random"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 86,
                "path": "src/randomutils/src/Shared/WeightedRandomChooser.lua"
            }
        }
    ],
    "properties": [],
    "types": [],
    "name": "WeightedRandomChooser",
    "desc": "",
    "source": {
        "line": 4,
        "path": "src/randomutils/src/Shared/WeightedRandomChooser.lua"
    }
}