{"id":"chipioindustries/random-selection","name":"random-selection","scope":"chipioindustries","platform":"roblox","description":"A module for selecting a random item from a weighted list.","version":"1.0.1","latest":"1.0.1","versions":["1.0.1"],"license":"AGPL-3.0","licenseRating":"unsafe","licenseCaveats":["Strongest copyleft: even network use counts as distribution, so running this in a live game plausibly requires releasing your game's entire source under AGPL-3.0. Not recommended for closed-source projects.","License identified from the packaged LICENSE file; the manifest declared none."],"licenseVerified":true,"dependencies":{"chipioindustries/llama":{"version":"^1.2.4","alias":"Llama"},"osyrisrblx/t":{"version":"^3.0.0","alias":"t"}},"integrity":"4084e7483d339ce9929e519ef4bf7b23fa3bd287ab6a665f789575a7c87abd25","likes":0,"downloads":0,"install":"forest install chipioindustries/random-selection","url":"https://forest.dev/p/roblox/chipioindustries/random-selection","files":"https://api.forest.dev/ai/package/roblox/chipioindustries/random-selection/files","readme":"# RandomSelection\n\nA module for selecting a random item from a weighted list.\n\n## API\n\nThe API consists of a single function that accepts a dictionary where each key is an item that corresponds to a numeric weight indicating its likelihood of being chosen. The function returns the item (key) of the random selection.\n\n```lua\nVariant getFromWeightedDictionary(Dictionary itemWeights)\n```\n\n## Usage\n\n```lua\nlocal RandomSelection = require(script.Parent.RandomSelection)\n\nlocal itemWeights = {\n\titem1 = 1; -- will be selected 20% of the time\n\titem2 = 2; -- will be selected 40% of the time\n\titem3 = 2; -- will be selected 40% of the time\n}\n\nlocal selectedItem = RandomSelection:getFromWeightedDictionary(itemWeights)\n\nprint(selectedItem) -- \"item1\", \"item2\", or \"item3\"\n```\n\n## Weight Dictionary Formatting\n\nThe typical structure is a dictionary of item names and weights:\n```lua\nlocal itemWeights = {\n\titem1 = 5;\n\titem2 = 10;\n\titem3 = 15;\n}\n```\n\nAny data type can be used, although **strings** are strongly recommended.\n\n```lua\nlocal items = script.Parent.ItemsFolder\nlocal itemWeights = {\n\t[items.Item1] = 5;\n\t[items.Item2] = 10;\n\t[items.Item3] = 15;\n}\nlocal selectedItem = RandomSelection:getFromWeightedDictionary(itemWeights)\nselectedItem:Clone()\n```\n\n```lua\nlocal itemWeights = { 5, 10, 15 }\nlocal selectedItem = RandomSelection:getFromWeightedDictionary(itemWeights)\nprint(itemWeights) -- 1, 2, or 3\n```\n\nDecimal weight values can be used.\n\n```lua\nlocal itemWeights = {\n\titem1 = 0.1;\n\titem2 = 0.6;\n\titem3 = 0.7;\n}\n```\n\nEmpty arrays will throw errors.\n\n```lua\nlocal itemWeights = {}\n-- the following line will error:\nRandomSelection:getFromWeightedDictionary(itemWeights)\n```\n","readmeTruncated":false}