Coding Decimal Probabilities

If there is any topic talking about this and SOLVING it please redirect me to it.

The issue i’m facing is basically that i need to have decimal probability(chances), something like 0.27% or 66.8%.

A way i found was the weighted method but its really one of the worst and it doesn’t have decimals , the other ways were bunch of complicated algebra that I couldn’t understand since there were no explanation to it.

After thinking about this issue for a while i came up with some sort of a trick to solve it but I don’t think its the best for performance and here is the explanation for it:

Before i get into the logic you need to know that if you multiplied a percent with another percent your basically getting the first percent out of the second one, for example 10% * 1% is 0.1% so here is the logic for it,

I basically have two chances, The first one is the chance of the item existing in the box and the second chance is the chance of getting it from the box if it existed in the first place so basically the first chance HAS to come true so that the second CAN come true,

so basically if i want 0.1% chance all i do is have the first table containing 10 elements and one of them is different than the 9 rest and if that different element was picked then i will put one copy of the item in the chest which contains 100 elements so the chance of pulling that item each time you do the calculation is the chance of the first table 1/10 which is 10% multiplied by the chance of the second table which is 1/100 which is 1% so the full calculation is (1/10) * 100 * (1/100) so its 0.1%,

As i said this prob takes a lot of resources specially if each player will be afk opening chests so i hope you guys can help, a perfect example of this system is the one used in ANIME FIGHTERS SIMULATOR Made by daireb.

Do you mean something like:

local chanceA = 0.5 -- Chance of it existing in the box (50%)
local chanceB = 0.01 -- Chance of getting it if it existed (1%)

local newChance = (chanceA * chanceB) * 100 -- 0.005 = 0.5% Chance
1 Like

Yea, the logic if you didn’t get it is that the first chance is the chance for it to exist in the box while the second chance is the chance to pull it if it existed in the first place so the total chance is both chances multiplied, but as i said i feel like this is terrible for performance thats why i need a better way to do it

It shouldn’t be terrible performance? Why would it be?

The way to implement this is by making two tables, the first one has 10 elements and the second one has 100 elements and thats if the chance is simple like 0.1% but if its like 0.37% or 0.0726% then both tables would have to be 100 elements, im not entirely sure if that would take a lot of resources or not and take in mind that the game has many other computations other than this and that this computation would be made for each player for idk how many times per minute depending on the game

Performing a multiplication doesn’t seem very intensive?

So your basically saying that this wouldn’t take any unnecessary resources from the game am i correct?

I don’t think so

1 Like

Well my only issue is figuring out how intense would that be if each player did it like 20 times per minute for example and a better solve would be a whole another way other than this if possible

20 times per minute shouldn’t be intensive at all?

1 Like