summaryrefslogtreecommitdiff
path: root/games/random
diff options
context:
space:
mode:
Diffstat (limited to 'games/random')
-rw-r--r--games/random/random.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/games/random/random.c b/games/random/random.c
index 9e9edb0ee09..94238dea7e7 100644
--- a/games/random/random.c
+++ b/games/random/random.c
@@ -52,6 +52,8 @@ static char rcsid[] = "$NetBSD: random.c,v 1.3 1995/04/22 07:44:05 cgd Exp $";
#include <sys/types.h>
+#include <dev/rndvar.h>
+
#include <err.h>
#include <errno.h>
#include <stdio.h>
@@ -68,12 +70,11 @@ main(argc, argv)
char *argv[];
{
extern int optind;
- time_t now;
double denom;
int ch, random_exit, selected, unbuffer_output;
char *ep;
- /* revoke */
+ /* revoke privs */
setegid(getgid());
setgid(getgid());
@@ -112,12 +113,9 @@ main(argc, argv)
/* NOTREACHED */
}
- (void)time(&now);
- srandom((u_int)(now + getpid()));
-
/* Compute a random exit status between 0 and denom - 1. */
if (random_exit)
- return ((denom * random()) / LONG_MAX);
+ return (arc4random() % (u_int32_t)denom);
/*
* Act as a filter, randomly choosing lines of the standard input
@@ -132,7 +130,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)(arc4random() % (u_int32_t)denom) == 0;
while ((ch = getchar()) != EOF) {
if (selected)
(void)putchar(ch);
@@ -142,7 +140,7 @@ 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)(arc4random() % (u_int32_t)denom) == 0;
}
}
if (ferror(stdin))