in reply to Rolling a biased die
With non-integer probabilities, you can do O(log2(n)), but given small n, O(n) is probably a draw (and the code will be simpler).
I suggest normalizing the biases so that they sum to 1.0. Then you can rand(1.0), rather than having to either store or calculate a rand limit.
|
---|