-/* $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
* 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.
*
#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 */
#include <unistd.h>
#include <limits.h>
-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)
}
(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
* 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);
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