PICKWEIGHT() DOESN'T WORK PROPERLY WITH DECIMAL NUMBERS OH MY
Created by: wwjnc
Since it uses rand(1, total)
to choose the item to pick and rand(x, y)
only returns integer numbers between x
and y
, you can potentially miss some options using decimal weights.
Example:
item | A | B | C |
---|---|---|---|
weight | 1 | 1 | 0.1 |
Since total = rand(1, total)
with total = 2.1
, you'll get either total = 1
or total = 2
, which would choose A or B, but never C. This is the reason why the balloon bundle never shows up on the syndie bundle.
I blame Dylan, oldcode and Lummox. Please log a warning when total
is not an integer, crash the server or turn on the panic bunker. And add proper documentation so this doesn't happen mysteriously again.
P.S. ALSO DON'T BE THIS GUY
//Pretends to pick an element based on its weight but really just seems to pick a random element.
/proc/pickweight(list/L)
// ...