note
tomazos
Cool algorithm. It's like a king of the hill match.
<P>
1 starts as king of the hill. ($rand = 1)
<P>
2 comes along and challanges it. Whoever wins stays on top (is assigned to $rand).
<P>
Just like 2, everyone else (3, 4, 5 and 6) gets a chance.
<P>
Whoever is left on top ($rand) is declared the winner. :)
<P>
<HR>
<P>
To understand why the probabilities work you have to step through the algorithm backwards.<P>
ie. What is the chance that 6 (the final iteration) is going to win it's match against the king of the hill? $bias{6} / sum(values %bias), which is obvious.
<P>
Now - consider the second last iteration (5). Given that 6 is going to have it's chance in a minute, and hence does not need to be included, what is the chance that 5 will win it's match? $bias{5} / (sum(values %bias) - $bias{6}). We remove 6 from the running by excluding it's weighting from the total.
<P>
<strong>Update:</strong> This explanation is awful. :)
158482
158490