]> git.lizzy.rs Git - rust.git/commitdiff
rollup merge of #20518: nagisa/weighted-bool
authorAlex Crichton <alex@alexcrichton.com>
Tue, 6 Jan 2015 02:37:25 +0000 (18:37 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 6 Jan 2015 02:37:25 +0000 (18:37 -0800)
1 in 1 chance to return true always results in true.

src/librand/lib.rs

index 9f44b7438ae214fc3adc0c85b309eedf37b1fdbf..f538e0ade05f5f5e1d32fe442c82a2389dbf7ae9 100644 (file)
@@ -243,7 +243,7 @@ fn gen_range<T: PartialOrd + SampleRange>(&mut self, low: T, high: T) -> T {
     /// println!("{}", rng.gen_weighted_bool(3));
     /// ```
     fn gen_weighted_bool(&mut self, n: uint) -> bool {
-        n == 0 || self.gen_range(0, n) == 0
+        n <= 1 || self.gen_range(0, n) == 0
     }
 
     /// Return an iterator of random characters from the set A-Z,a-z,0-9.