Answer the question
In order to leave comments, you need to log in
How to realize the chance?
How can you realize the chance to perform some action?
For example, there are 3 actions and the following chances are given for them:
1. 20%
2. 40%
3. 60%
How to choose a random action?
There is an idea to add up all the chances, it will turn out 20 + 40 + 60 = 120, then through rand choose a random value from 120, and which number will fall out - then the action will be. But if there is any action with a 100% chance to stand, then this method will not work ... tell me how best to do it?
Answer the question
In order to leave comments, you need to log in
You are pointing percentages in vain, this is not correct. 20, 40, 60 are just hit probability multipliers. So even if there are 20, 40, 60, 100 - this will not be a problem. Count rand(0, 20+40+60+100), then determine what limits the number falls into.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question