Help choosing a random weighted value from a table except the already chosen value

I need help choosing a value from a table that is weighted, i.e has a chance to be chosen but I also need to exclude an already chosen value from said table, for example if a player has a specific race from a list of races, I want them to be able to randomly roll another ( weighted ) from said list without choosing their same race again.

The two methods I’m thinking are to either, A simply use repeat until on a function until it returns a desired value that is not equal to the previous value, but this would have other consequences such as the other race percentages not adjusting ( from my understanding ).

I think it would be better if I had a master table and a temporary table, and simply duplicate the master to the temporary table and then remove their chosen race from the list and then perform whatever actions I need on that list.

Would appreciate any ideas, code examples etc and I am more than happy to elaborate further if anyone has any questions.

The simplest one if the repeat until the chosen is not equal to ~=
(I don’t personally understand what you mean by percentages not adjusting)

The master table idea can work as well. Really just depends which is best. Implement the repeat until one and if it doesn’t grant the results, try the other one. If that doesn’t grant good results combine the two.

Well for example, the current race would still be apart of the percentages table, so let’s say it takes up 20% of the total chances, wouldn’t it be better to remove that 20% and redistribute it to the other ones to adjust the chances to be more accurate?

OH!! Ok, now I understand.

Yea, do the master table/dictionary and with the chance (ex. 20%) that is left over, divide it into the other ones left.

Kind of bad at math, how would you go about dividing it into the other chances? Assuming those chances are all preset like " 1% " etc Would I just equally split it?

It gonna get difficult, as you need to make sure that when your split it that you round it (so no decimal points) What you would do is get the number of items left in the table and divide the leftover value by those items in the table. Make sure you use math.floor() after you get that result.

I would suggest utilizing a temporary table and master table for a solution to your desired outcome.

The master table could contain the possible races for players to choose from, while the temporary table would contain all of the races that a player has not yet chosen.

Once a player has chosen a race, the race could be removed from the temporary table and the remaining races could be sorted randomly to allow for more weighted selection.

By utilizing this dual-table approach, you could ensure that players are not presented with the same race twice while also allowing for weighted chances of selection.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.