Simplify uniform range transformation.
authormdw <mdw>
Wed, 6 Dec 2000 20:31:06 +0000 (20:31 +0000)
committermdw <mdw>
Wed, 6 Dec 2000 20:31:06 +0000 (20:31 +0000)
fibrand.c
grand.c
lcrand.c

index 950fd76..6856a57 100644 (file)
--- a/fibrand.c
+++ b/fibrand.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: fibrand.c,v 1.2 2000/06/17 10:55:24 mdw Exp $
+ * $Id: fibrand.c,v 1.3 2000/12/06 20:31:06 mdw Exp $
  *
  * Fibonacci generator
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: fibrand.c,v $
+ * Revision 1.3  2000/12/06 20:31:06  mdw
+ * Simplify uniform range transformation.
+ *
  * Revision 1.2  2000/06/17 10:55:24  mdw
  * Typesetting fixes.  Add flags word to generatic random generator.
  *
@@ -149,7 +152,7 @@ uint32 fibrand_range(fibrand *f, uint32 m)
   /* --- Now generate numbers until a good one comes along --- */
 
   do x = fibrand_step(f); while (x >= r);
-  return (x / (r / m));
+  return (x % m);
 }
 
 /*----- Generic interface -------------------------------------------------*/
diff --git a/grand.c b/grand.c
index 0f9eee5..b7118ab 100644 (file)
--- a/grand.c
+++ b/grand.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: grand.c,v 1.1 1999/12/10 23:16:01 mdw Exp $
+ * $Id: grand.c,v 1.2 2000/12/06 20:31:06 mdw Exp $
  *
  * Generic interface to random number generators
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: grand.c,v $
+ * Revision 1.2  2000/12/06 20:31:06  mdw
+ * Simplify uniform range transformation.
+ *
  * Revision 1.1  1999/12/10 23:16:01  mdw
  * Generic interface.
  *
@@ -126,7 +129,6 @@ uint32 grand_range(grand *r, uint32 l)
      */
 
     z = m - (m % l);
-    m = z / l;
 
     /* --- Generate numbers until something acceptable is found --- *
      *
@@ -134,7 +136,7 @@ uint32 grand_range(grand *r, uint32 l)
      */
 
     do x = w(r); while (x >= z);
-    return (x / m);
+    return (x % l);
   }
 }
 
index 05c3aae..f53a3f2 100644 (file)
--- a/lcrand.c
+++ b/lcrand.c
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: lcrand.c,v 1.3 2000/06/17 11:29:03 mdw Exp $
+ * $Id: lcrand.c,v 1.4 2000/12/06 20:31:06 mdw Exp $
  *
  * Simple linear congruential generator
  *
@@ -30,6 +30,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: lcrand.c,v $
+ * Revision 1.4  2000/12/06 20:31:06  mdw
+ * Simplify uniform range transformation.
+ *
  * Revision 1.3  2000/06/17 11:29:03  mdw
  * Add the flags word to the generic generator.
  *
@@ -178,7 +181,7 @@ uint32 lcrand_range(uint32 *x, uint32 m)
   uint32 r = P - P % m;
   do xx = lcrand(xx); while (xx >= r);
   *x = xx;
-  return (xx / (r / m));
+  return (xx % m);
 }
 
 /*----- Generic interface -------------------------------------------------*/