diff options
author | kstailey <kstailey@cvs.openbsd.org> | 1997-10-01 19:06:31 +0000 |
---|---|---|
committer | kstailey <kstailey@cvs.openbsd.org> | 1997-10-01 19:06:31 +0000 |
commit | 49af38125e3102bc06b8bb3406dc5ab509b77d82 (patch) | |
tree | 89e58ab9439716974b7e649e82a62eebf19d12f3 /games | |
parent | d0619fcc8d10362609050133bd2f1a9b68894aa2 (diff) |
use arc4random
Diffstat (limited to 'games')
-rw-r--r-- | games/random/random.c | 14 |
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)) |