rust-random / rand

A Rust library for random number generation.
https://crates.io/crates/rand
Other
1.6k stars 423 forks source link

Question regarding match statement in `uniform.rs` -> Sample single value, Canon's method, unbiased. #1433

Closed Thell closed 2 months ago

Thell commented 2 months ago

In sample_single_inclusive with feature unbiased: https://github.com/rust-random/rand/blob/bca078e929bdf2a1e1730cf394e497e3d0732605/src/distributions/uniform.rs#L620

If checked_add performs addition that returns None instead of wrapping around on overflow then won't it always return either a value or None? If so, when would the default case ever happen? And, if it never happens then shouldn't it be removed? And, if it should be removed then isn't it then the same as the sample_single_value without the unbiased feature (Canon's method, biased)?

Thell commented 2 months ago

Never mind, I was totally forgetting the conditional part of the Some(x) match. Sorry.