Dom Pedro II
Modder For Life
I'm trying to come up with a way to create a weighted probability for randomly generated values. For example, if I want the game to pick a technology or unit at random to give to a player, it's easy to have it pick one with an equal chance of selecting any one.
For example, in my Extra Pillage mod, when a pillaged improvement gives research, it checks all the available techs and sees which are elligible, then randomly picks one tech of that shortened list and gives research points towards it.
But what if I want to make it so that there's a 60% chance of it choosing one, and maybe %20 chance of another, 10% of another, etc. etc.
I'm not great with math, so I'm not sure how one would create this kind of system. I've developed a couple of ideas, but none really satisfy me. The best I've come up with so far is adding multipliers for the different choices and then having the game generate a random number for each choice, multiply it by the multiplier and take the largest number. The problem comes in trying to predict the probability of any of the results...
For example, in my Extra Pillage mod, when a pillaged improvement gives research, it checks all the available techs and sees which are elligible, then randomly picks one tech of that shortened list and gives research points towards it.
But what if I want to make it so that there's a 60% chance of it choosing one, and maybe %20 chance of another, 10% of another, etc. etc.
I'm not great with math, so I'm not sure how one would create this kind of system. I've developed a couple of ideas, but none really satisfy me. The best I've come up with so far is adding multipliers for the different choices and then having the game generate a random number for each choice, multiply it by the multiplier and take the largest number. The problem comes in trying to predict the probability of any of the results...