weighted_randomizer
weighted_randomizer copied to clipboard
Incorrect pick and weight comparison
I know it's abandoned gem. But seems like here should be < instead of <=.
The lib normalizes {zero: 0, one: 1} to {zero: 0.0, one: 1.0}.
It's obvious that :zero can never be sampled. But rand method can return value 0.0, then pick = 0.0, and then return key if pick <= weight returns :zero since 0.0 <= 0.0 evaluates to true.