]> git.lizzy.rs Git - rust.git/commitdiff
Do not use entropy during gen_weighted_bool(1)
authorSimonas Kazlauskas <git@kazlauskas.me>
Sun, 4 Jan 2015 12:58:08 +0000 (14:58 +0200)
committerSimonas Kazlauskas <git@kazlauskas.me>
Sun, 4 Jan 2015 12:58:08 +0000 (14:58 +0200)
1 in 1 chance to return true always results in true.

src/librand/lib.rs

index 0f8dbc78cde3272c8ee62d2da768f1e16abeb65f..18f508e816f2b772713b8ad2a8f278b4e8467373 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.