In this post I describe the common problem how to generate random weighted variables. For example you have a die with 6 faces that is fixed, so the probability of an 1 is not the same with the probability of a 2 etc.
The table below shows an example:
One easy solution is to reduce the problem to another one with a die with 100 faces that is not fixed.
You generate a random value from 0-99 that follows the uniform distribution. Do not use the modulo function to do that. See this post instead.
Once you have that value you perform the following steps:
You check the space within which that value relies.
- between 0 and 24, you generate 1 as the weighted variable
- between 25 and 49, you generate 2 as the weighted variable
- between 50 and 69, you generate 3 as the weighted variable
- between 70 and 89, you generate 4 as the weighted variable
- between 90 and 94, you generate 5 as the weighted variable
- between 95 and 99, you generate 6 as the weighted variable