Fix bug where Rand64::rand_range always starts from 0.

Also adds a unit test for it, and changes the const's used in
a couple unit tests just to mix things up a bit.

Should resolve issue #3.
1 files changed, 24 insertions(+), 3 deletions(-)

M src/lib.rs
M src/lib.rs +24 -3
@@ 256,7 256,7 @@ impl Rand64 {
                 leftover = (m & 0xFFFFFFFF_FFFFFFFF) as u64;
             }
         }
-        (m.wrapping_shr(64)) as u64
+        (m.wrapping_shr(64)) as u64 + range.start
     }
 }
 

          
@@ 392,9 392,9 @@ mod tests {
     }
 
     #[test]
-    fn test_randrange() {
+    fn test_randrange32() {
         // Make sure ranges are valid and in the given range
-        let seed = 2342_4223;
+        let seed = 2342_3141;
         let mut r1 = Rand32::new(seed);
         for _ in 0..1000 {
             // Generate our bounds at random

          
@@ 413,6 413,27 @@ mod tests {
     }
 
     #[test]
+    fn test_randrange64() {
+        // Make sure ranges are valid and in the given range
+        let seed = 2342_2718;
+        let mut r1 = Rand64::new(seed);
+        for _ in 0..1000 {
+            // Generate our bounds at random
+            let a = r1.rand_u64();
+            let b = r1.rand_u64();
+            if a == b {
+                continue;
+            }
+            let (low, high) = if a < b { (a, b) } else { (b, a) };
+
+            // Get a number in that range
+            let in_range = r1.rand_range(low..high);
+            assert!(in_range >= low);
+            assert!(in_range < high);
+        }
+    }
+
+    #[test]
     fn test_rand32_vs_rand() {
         use rand_core::RngCore;
         use rand_pcg;