Author Topic: Suggestions For Randomization  (Read 520 times)

Writing some code.
I have ten groups(0-9). I need to randomly select one of them, but each higher up group needs to have a lower change of being selected. There may also be gaps in the sequence; like the only groups I want to select from might be 0, 5, and 6. Or it might b 3, 7, and 9. Or it might be all of them. Any suggestions.

Well, you could subtract the number from 10. So, 10-9 = 1, 10-8 = 2, 10-3 = 7 and so on. Summing those together gives us 55, so you could then generate a number between 1 and 55. Now, we give group 9 one chance, as 10-9 = 1, and we give group 8 two chances, and so on.

IndexChancesStarting ValueEnding ValueProbability
01011010/55 = 18%
1911199/55 = 16%
2820278/55 = 14%
3728347/55 = 12%
4635406/55 = 10%
5541455/55 = 9.1%
6446494/55 = 7.2%
7350523/55 = 5.5%
8253542/55 = 3.6%
9155551/55 = 1.8%

Now, it really does depend on how much you want the probability to scale. That above is linear. That also doesn't account for changing groups, but I hope that at least somewhat helps.

Thanks. This helps a lot. I was trying to do something similar, but a bit wrong. This helped me wrap my mind around it.