Skip to content

Incorrect pick and weight comparison #3

@airled

Description

@airled

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions