File tree 1 file changed +10
-0
lines changed
1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -515,6 +515,16 @@ pub trait Rng: RngCore {
515
515
/// let mut rng = thread_rng();
516
516
/// println!("{}", rng.gen_bool(1.0 / 3.0));
517
517
/// ```
518
+ ///
519
+ /// # Accuracy note
520
+ ///
521
+ /// `gen_bool` uses 32 bits of the RNG, so if you use it to generate close
522
+ /// to or more than 2^32 results, a tiny bias may become noticable.
523
+ /// A notable consequence of the method used here is that the worst case is
524
+ /// `rng.gen_bool(0.0)`: it has a chance of 1 in 2^32 of being true, while
525
+ /// it should always be false. But using `gen_bool` to consume *many* values
526
+ /// from an RNG just to consistently generate `false` does not match with
527
+ /// the intent of this method.
518
528
fn gen_bool ( & mut self , p : f64 ) -> bool {
519
529
assert ! ( p >= 0.0 && p <= 1.0 ) ;
520
530
// If `p` is constant, this will be evaluated at compile-time.
You can’t perform that action at this time.
0 commit comments