From dce0d0db51d4e566d4505e87d2856d230ce94b14 Mon Sep 17 00:00:00 2001 From: mdw Date: Wed, 6 Dec 2000 20:31:06 +0000 Subject: [PATCH] Simplify uniform range transformation. --- fibrand.c | 7 +++++-- grand.c | 8 +++++--- lcrand.c | 7 +++++-- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/fibrand.c b/fibrand.c index 950fd76..6856a57 100644 --- 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 --- 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); } } diff --git a/lcrand.c b/lcrand.c index 05c3aae..f53a3f2 100644 --- 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 -------------------------------------------------*/ -- 2.11.0