X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/82852318e37fa7eddacc3dd162a2d16d3a7487b9..3748e584d42e73bc48d6b26c52a093ad7d77732c:/random/random.c diff --git a/random/random.c b/random/random.c index f817a5d8..6b024f74 100644 --- a/random/random.c +++ b/random/random.c @@ -1,4 +1,4 @@ -/* $NetBSD: random.c,v 1.6 1999/09/08 21:45:29 jsm Exp $ */ +/* $NetBSD: random.c,v 1.10 2005/08/10 14:02:26 rpaulo Exp $ */ /* * Copyright (c) 1994 @@ -15,11 +15,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -46,7 +42,7 @@ __COPYRIGHT("@(#) Copyright (c) 1994\n\ #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.10 2005/08/10 14:02:26 rpaulo Exp $"); #endif #endif /* not lint */ @@ -61,8 +57,10 @@ __RCSID("$NetBSD: random.c,v 1.6 1999/09/08 21:45:29 jsm Exp $"); #include #include -int main __P((int, char **)); -void usage __P((void)) __attribute__((__noreturn__)); +#define MAXRANDOM 2147483647 + +int main(int, char **); +void usage(void) __attribute__((__noreturn__)); int main(argc, argv) @@ -111,11 +109,11 @@ main(argc, argv) } (void)gettimeofday(&tp, NULL); - srandom((u_int)(tp.tv_usec + tp.tv_sec + getpid())); + srandom((unsigned long)tp.tv_usec + tp.tv_sec + getpid()); /* 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 +128,7 @@ main(argc, argv) * 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,12 +138,14 @@ main(argc, argv) 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)) err(2, "stdin"); exit (0); + + return 0; } void