weighted_randomizer icon indicating copy to clipboard operation
weighted_randomizer copied to clipboard

Incorrect pick and weight comparison

Open airled opened this issue 2 years ago • 0 comments

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.

airled avatar Sep 16 '23 13:09 airled