How to distribute ratios randomly with min and max values

so i am trying to do a sort of slot system ig u could call it

local slots = 32
local tablee = {ThingA = {min = 1,max = 2},
ThingB = {min = 2,max = 5},
thingC = {min = 25,29}}

so basically the min and max values are for how many slots a certain item takes i need to randomly pick a value for slots in this range while the sum of all the values being 32 how do i do this

1 Like

I would do the random on thingC, then use the remainder of slots - thingC as the bounds for the next random, based upon the min possible values for thingB + thingA. Then thingA bounds become whatever is left.
What I am trying to say is that your max value is always based upon the preceding random value, working backwards from highest to lowest.
If that makes sense

1 Like

but doesnt tht decrease the chances of thingA getting high values (the current table is just for example)

I can’t think of a good, elegant solution for this now, either.

One way to do it would be to put maximum amounts of the three items in a table, shuffle the table and take 32 items from the table.
i.e. create a table {A, A, B, B, B, B, B, C, C, C, C...}, shuffle, take 32.

One problem with that is that you might get 0 of ThingA if both of them end up beyond the 32nd item.

You specify minimum amounts of each item: 1 A, 2 B, 25 C- which leaves you with 4 slots that are undecided.
Pick random items into these slots.
For example, take 4 items from this 8-item list: {A, B, B, B, C, C, C, C}
Unfortunately, A has only a 1/8 chance of taking 2 slots instead of 1

1 Like