There is a bag of 10 marbles, 5 red and 5 black. You reach in and take a marble, what is the probability that you take a red marble? a black marble?
Now there is a bag with 10 marbles, 3 red, 2 yellow, and 5 black. What is the probability that you get take a red marble? a black marble? a yellow marble?
Now, lets say these marbles are put in a row in front of you and numbered 0 to 9.
It would looks something like this
[r, r, r, y, y, b, b, b, b, b]
Lets say that the example above are the 0th, 1st, 2nd, 3rd, 4th, 5th, 6th, 7th, 8th, and 9th marbles in the row.
Now roll a 10 sided dice, and do modular division on the result. 10 % 10 (modular division) = 0
Therefore,
1 % 10 = 1
2 % 10 = 2
3 % 10 = 3
4 % 10 = 4
5 % 10 = 5
6 % 10 = 6
7 % 10 = 7
8 % 10 = 8
9 % 10 = 9
10 % 10 = 0
Whatever the result of rolling the 10 sided dice (which is random) modularly divided by 10 is now the marble you choose to remove.
This happens to be a (simplified) way of how this is done in general for any number of N items that you need to randomly select from.
This is also (without looking at source code) how this is done for Rune of Removal (more or less). The only difference being, once you roll, say a 2 on the 10 sided dice, you now have to remove all red marbles from the row. Because Rune of Removal randomly (dice roll) selects an affix to remove, all it does is weight (different number of red or yellow or black marbles in the row = different probabilities to be selected) based on the number of tiers that affix has.