Clever random?
Here''s a simple question.
I have a set of choices and each choice has a probability in percents. (Alltogether they give 100%). What''s the algo to choose one based on their probability of happening?
Just choose a random 100% ?
For instance (psuedo code, should work)
For instance (psuedo code, should work)
Choice(1) = 10 (10% probability)Choice(2) = 50 (50% probability)Choice(3) = 40 (40% probability)RandomValue = Random(100) (Random value between 0 and 99)ChoiceIndex = 1Do While Choice(ChoiceIndex) < RandomValue RandomValue = RandomValue - Choice(ChoiceIndex) ChoiceIndex = ChoiceIndex + 1Loop
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement