-
-
Notifications
You must be signed in to change notification settings - Fork 470
Open
Labels
D-has-PRIssue is waiting on an existing PR being mergedIssue is waiting on an existing PR being mergedX-bugType: bug reportType: bug report
Description
I mistakenly assumed that choose_multiple
functions like Python's random.choices
, which performs sampling with replacement. This led to unexpected behaviour in the following Rust code:
let sample = 5..20.choose_multiple(&mut rng, my_vec.len())
Here, my_vec
contains significantly more than 15 elements, but sample ends up with only 15 elements. This behaviour can be surprising and may introduce bugs.
Since choose_multiple
performs sampling without replacement, it would make more sense for it to return a Result
or Option
to return error or None
when the requested number of elements cannot be selected without replacement.
Metadata
Metadata
Assignees
Labels
D-has-PRIssue is waiting on an existing PR being mergedIssue is waiting on an existing PR being mergedX-bugType: bug reportType: bug report