Let’s say we want the probability of choosing a row to be (rank of this row / total rank of all rows). This would ensure that a row with a rank of 20 gets chosen exactly two times as often as a row with rank 10, and so on – lovely, and we don’t need to rewrite all the numbers if we decide to take out one of the earlier rows. Here’s some (untested, so there may be small mistakes) code that would do that:
[code]Total rank is a number that varies.
To calculate total rank:
let m be 0;
repeat through the Table of Exploration:
increase m by rank entry;
now total rank is m.
To decide which number is chosen row:
calculate total rank;
let x be a random number between 1 and total rank;
repeat with n running from 1 to the number of rows in the Table of Exploration:
choose row n in the Table of Exploration;
if x is not greater than rank entry:
decide on n;
decrease x by rank entry;
decide on 1. [This should never happen.]
[/code]
And we can now use the phrase “choose row chosen row in the Table of Exploration”.
(To see how the algorithm works, let’s say that the rank entries are 5, 10, 20 and 7. That means total rank evaluates to 5 + 10 + 20 + 7 = 42. We choose a random number between 1 and 42. If it is not greater than 5 (probability 5/42), we choose the first row. If it is greater than 5, we decrease it by 5, leaving us with a random number between 1 and 37. If this is not greater than 10 (total probability 10 / 42), we choose the second row. If not, we decrease it by 10… and so on.)