--- sam_k_uniform_int.hpp	2004-08-23 18:53:56.000000000 +0000
+++ sam_k2_uniform_int.hpp	2004-08-23 19:52:46.000000000 +0000
@@ -64,8 +64,8 @@
   result_type operator()(Engine& eng)
   {
     typedef typename Engine::result_type base_result;
-    base_result bmin = (eng.min)();
-    base_result brange = (eng.max)() - (eng.min)();
+    const base_result bmin = (eng.min)();
+    const base_result brange = (eng.max)() - (eng.min)();
 
     if(_range == 0) {
       return _min;    
@@ -104,19 +104,16 @@
           return result + _min;
       }
     } else {                   // brange > range
-      if(brange / _range > 4 /* quantization_cutoff */ ) {
-        // the new range is vastly smaller than the source range,
-        // so quantization effects are not relevant
-        return boost::uniform_smallint<result_type>(_min, _max)(eng);
-      } else {
-        // use rejection method to handle cases like 0..5 -> 0..4
-        for(;;) {
-          base_result result = eng() - bmin;
-          // result and range are non-negative, and result is possibly larger
-          // than range, so the cast is safe
-          if(result <= static_cast<base_result>(_range))
-            return result + _min;
-        }
+      // use rejection method to handle cases like 0..5 -> 0..4
+      const base_result casted_range = static_cast<base_result>(_range);
+      const base_result scale = brange / (casted_range+1);
+      // we always have scale *(casted_range+1) <= brange, no overflow.
+      const base_result rejec_thresh = scale * (casted_range+1);
+      for(;;) {
+        base_result result = eng() - bmin;
+        if(result < rejec_thresh)
+            return result/scale + _min;
+        
       }
     }
   }
