]> git.lizzy.rs Git - rust.git/blobdiff - src/librand/lib.rs
rollup merge of #20518: nagisa/weighted-bool
[rust.git] / src / librand / lib.rs
index 1d37b061c97121ce6821952b0fe304b271e3410b..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.
@@ -385,6 +385,7 @@ pub trait SeedableRng<Seed>: Rng {
 /// RNGs"](http://www.jstatsoft.org/v08/i14/paper). *Journal of
 /// Statistical Software*. Vol. 8 (Issue 14).
 #[allow(missing_copy_implementations)]
+#[deriving(Clone)]
 pub struct XorShiftRng {
     x: u32,
     y: u32,
@@ -392,17 +393,6 @@ pub struct XorShiftRng {
     w: u32,
 }
 
-impl Clone for XorShiftRng {
-    fn clone(&self) -> XorShiftRng {
-        XorShiftRng {
-            x: self.x,
-            y: self.y,
-            z: self.z,
-            w: self.w,
-        }
-    }
-}
-
 impl XorShiftRng {
     /// Creates a new XorShiftRng instance which is not seeded.
     ///
@@ -507,6 +497,7 @@ fn rand<R: Rng>(rng: &mut R) -> XorShiftRng {
 #[cfg(not(test))]
 mod std {
     pub use core::{option, fmt}; // panic!()
+    pub use core::clone; // derive Clone
     pub use core::kinds;
 }