Skip to content

inaccurate probabilities in IteratorRandom::choose() #1058

@kazcw

Description

@kazcw

IteratorRandom::choose() uses a floating-point reciprocal to calculate probabilities. f64 reciprocal is an inexact operation with residuals on the order of 1 / 2^54.

For example: the probability of gen_bool(1.0 / 3) == true is: 6004799503160661/18014398509481984, which differs from 1/3 in the 17th digit.
An exact implementation of choose would be possible with gen_range.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions