Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games/random Define and use MAXRANDOM instead of LONG_MAX.



details:   https://anonhg.NetBSD.org/src/rev/9f552573c33e
branches:  trunk
changeset: 480704:9f552573c33e
user:      jsm <jsm%NetBSD.org@localhost>
date:      Tue Jan 18 16:12:25 2000 +0000

description:
Define and use MAXRANDOM instead of LONG_MAX.

diffstat:

 games/random/random.c |  12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diffs (54 lines):

diff -r 6f0d37e35ccf -r 9f552573c33e games/random/random.c
--- a/games/random/random.c     Tue Jan 18 13:58:07 2000 +0000
+++ b/games/random/random.c     Tue Jan 18 16:12:25 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: random.c,v 1.6 1999/09/08 21:45:29 jsm Exp $   */
+/*     $NetBSD: random.c,v 1.7 2000/01/18 16:12:25 jsm Exp $   */
 
 /*
  * Copyright (c) 1994
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)random.c   8.6 (Berkeley) 6/1/94";
 #else
-__RCSID("$NetBSD: random.c,v 1.6 1999/09/08 21:45:29 jsm Exp $");
+__RCSID("$NetBSD: random.c,v 1.7 2000/01/18 16:12:25 jsm Exp $");
 #endif
 #endif /* not lint */
 
@@ -61,6 +61,8 @@
 #include <unistd.h>
 #include <limits.h>
 
+#define MAXRANDOM      2147483647
+
 int  main __P((int, char **));
 void usage __P((void)) __attribute__((__noreturn__));
 
@@ -115,7 +117,7 @@
 
        /* Compute a random exit status between 0 and denom - 1. */
        if (random_exit)
-               return ((denom * random()) / LONG_MAX);
+               return ((denom * random()) / MAXRANDOM);
 
        /*
         * Act as a filter, randomly choosing lines of the standard input
@@ -130,7 +132,7 @@
         * 0 (which has a 1 / denom chance of being true), we select the
         * line.
         */
-       selected = (int)(denom * random() / LONG_MAX) == 0;
+       selected = (int)(denom * random() / MAXRANDOM) == 0;
        while ((ch = getchar()) != EOF) {
                if (selected)
                        (void)putchar(ch);
@@ -140,7 +142,7 @@
                                err(2, "stdout");
 
                        /* Now see if the next line is to be printed. */
-                       selected = (int)(denom * random() / LONG_MAX) == 0;
+                       selected = (int)(denom * random() / MAXRANDOM) == 0;
                }
        }
        if (ferror(stdin))



Home | Main Index | Thread Index | Old Index