summaryrefslogtreecommitdiffstats
path: root/games
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1997-03-30 23:33:29 +0000
committerache <ache@FreeBSD.org>1997-03-30 23:33:29 +0000
commitd2ba14107c688d7aa26e4722e08c1c6dc91068bb (patch)
tree38b9f064ee2d7f39364a67440b88624a3036d942 /games
parentf673899804337487c03c460fe7cbebca19789781 (diff)
downloadFreeBSD-src-d2ba14107c688d7aa26e4722e08c1c6dc91068bb.zip
FreeBSD-src-d2ba14107c688d7aa26e4722e08c1c6dc91068bb.tar.gz
Use srandomdev() now
Add range checking for invalid denominator values
Diffstat (limited to 'games')
-rw-r--r--games/random/random.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/games/random/random.c b/games/random/random.c
index acb882b..4d17b53 100644
--- a/games/random/random.c
+++ b/games/random/random.c
@@ -62,7 +62,6 @@ main(argc, argv)
char *argv[];
{
extern int optind;
- time_t now;
double denom;
int ch, random_exit, selected, unbuffer_output;
char *ep;
@@ -94,16 +93,18 @@ main(argc, argv)
denom = strtod(*argv, &ep);
if (errno == ERANGE)
err(1, "%s", *argv);
- if (denom == 0 || *ep != '\0')
+ if (denom <= 0 || *ep != '\0')
errx(1, "denominator is not valid.");
+ if (random_exit && denom > 255)
+ errx(1, "denominator must be <= 255 for random exit.");
break;
default:
usage();
/* NOTREACHED */
}
- (void)time(&now);
- srandom((unsigned long)(now ^ getpid()));
+ if (srandomdev() < 0)
+ srandom(time(NULL) ^ getpid());
/* Compute a random exit status between 0 and denom - 1. */
if (random_exit)
OpenPOWER on IntegriCloud