Open
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.