• Chance for random table selection
    3 replies, posted
I want to have a table full of items then have a chance for each item. Something like this local Items = { {name = Item, chance = 25}, {name = item2, chance = 50}, {name = Item3, chance = 1} } I know that there is table.random but that just chooses a random item. I want it to take the chances that way if an item has a higher chance then it will be chosen more likely
Assuming you're fine with sorting the items table based on chance, something like this'll work. https://gist.github.com/bigdogmat/e1e3229e23019c36fbd45bb8ccc6d113
This is working fine for one item but how could i expand this to choose like 3 items because i have like 10 items set at 100 and 2 items set at 10 and i seem to get the items set at 10 every time
You would just run the same code I posted (everything below line 13) 3 times. Or if you're always going to pick 3 items then yeah you could use 3 different picks and 3 different sums such that you only have to use 1 loop. This solution seems to be the one you came to.
Sorry, you need to Log In to post a reply to this thread.