And impossible to do well if your weights are sqrt(2), sqrt(5) and sqrt(11).
[Knuth vs BrowserUK] So O(N(/2)) compared to O(1).
Not quite a fair comparison, is it? You give yourself a preprocessing complexity of Ω(R) (in both time and memory), where R is the sum of all weights (and could hence be much larger than N), while you don't give Knuth any.
In reply to Re^4: Weighted random selection
by JavaFan
in thread Weighted random selection
by cosmicperl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |