mardi 17 octobre 2023

How do I use math to calculate the percentages of events happening

I'm creating a mod that will list the percent chance of an event happening. I know how to get individual percentages, but not a total percentage of the events.

So there is this pool, or an array of possible outcomes. Classic is always in this pool.

Bifurcated has a 15% chance of being added to that pool
Golden has a 0.3% chance of being added
Meaty has a 10% multiplied by the amount of X upgraded to be added. X=(max 3, min 0)
Caramelized has a 2% chance to be added.

And if another upgrade has been bought, all bought Classic get their checks done again, so there is a chance that there is : two, one, or none of being added to the pool.

Now the game takes this pool, and chooses one randomly from it. They have equal chances once in the pool. But not equal chances to enter the pool.

I'm having a hard time figuring out how to write the math to automatically calculate the chances are for each item. For example, if it was just Classic and Bifurcated a 15% chance to be added then a 50% chance to be selected would be 7.5% chance while classic has a 92.5% chance. But once I get to the possibility of a third being added, how do I calculate that?

After a lot of thinking, I came up with this system of adding them to the pool.

//chances of just ADDING bifurcated to the pool.
//RAN ONCE
let ranOnce_addOne = 0.15;
let ranOnce_addNone = 0.85;
//RAN TWICE
let ranTwice_addNone = 0.7225;
let ranTwice_addTwo = 0.0225;
let ranTwice_addOne = 0.225;

I had this, and didn't know where to go from here. For example if we only checked to add bifurcated to the pool once, I could figure it out, but the fact there are times when the amount in the pool could go from 1 to 9 (though statistically unlikely).

Now I have access to the amount of X and whether the checks get ran twice or not. But I have no idea how to code something that will tell me what is the chances of all this?




Aucun commentaire:

Enregistrer un commentaire