From f42126e4a69216894f2476f998079c17944a8562 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sun, 13 Jul 2014 14:01:05 +0000 Subject: if not seeded explicitly, use arc4random instead. ok deraadt --- games/atc/extern.h | 3 ++- games/atc/main.c | 6 ++---- games/atc/update.c | 27 ++++++++++++++++++++++----- 3 files changed, 26 insertions(+), 10 deletions(-) (limited to 'games') diff --git a/games/atc/extern.h b/games/atc/extern.h index 0c7351b5892..1e1a293b70b 100644 --- a/games/atc/extern.h +++ b/games/atc/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.7 2013/10/25 21:57:10 millert Exp $ */ +/* $OpenBSD: extern.h,v 1.8 2014/07/13 14:01:04 tedu Exp $ */ /* $NetBSD: extern.h,v 1.4 1995/04/27 21:22:22 mycroft Exp $ */ /*- @@ -102,6 +102,7 @@ void quit(int); int read_file(const char *); void redraw(void); void rezero(void); +void setseed(const char *); void setup_screen(const C_SCREEN *); int too_close(const PLANE *p1, const PLANE *p2, int); void update(int); diff --git a/games/atc/main.c b/games/atc/main.c index 7262502dd2f..c406822e774 100644 --- a/games/atc/main.c +++ b/games/atc/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.22 2014/07/13 13:00:40 tedu Exp $ */ +/* $OpenBSD: main.c,v 1.23 2014/07/13 14:01:04 tedu Exp $ */ /* $NetBSD: main.c,v 1.4 1995/04/27 21:22:25 mycroft Exp $ */ /*- @@ -112,9 +112,7 @@ main(int ac, char *av[]) } } if (seed != NULL) - srandom(atol(seed)); - else - srandomdev(); + setseed(seed); if (f_usage) fprintf(stderr, diff --git a/games/atc/update.c b/games/atc/update.c index 7eb9996c54c..f6d09de48e6 100644 --- a/games/atc/update.c +++ b/games/atc/update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: update.c,v 1.13 2014/07/13 13:00:40 tedu Exp $ */ +/* $OpenBSD: update.c,v 1.14 2014/07/13 14:01:04 tedu Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -43,6 +43,23 @@ #include "include.h" +int seeded; +void +setseed(const char *seed) +{ + seeded = 1; + srandom(atol(seed)); +} + +uint32_t +atcrandom() +{ + if (seeded) + return random(); + else + return arc4random(); +} + void update(int dummy) { @@ -196,7 +213,7 @@ update(int dummy) * Otherwise, prop jobs show up *on* entrance. Remember that * we don't update props on odd updates. */ - if ((random() % sp->newplane_time) == 0) + if ((atcrandom() % sp->newplane_time) == 0) addplane(); } @@ -292,10 +309,10 @@ addplane(void) memset(&p, 0, sizeof (p)); p.status = S_MARKED; - p.plane_type = random() % 2; + p.plane_type = atcrandom() % 2; num_starts = sp->num_exits + sp->num_airports; - rnd = random() % num_starts; + rnd = atcrandom() % num_starts; if (rnd < sp->num_exits) { p.dest_type = T_EXIT; @@ -308,7 +325,7 @@ addplane(void) /* loop until we get a plane not near another */ for (i = 0; i < num_starts; i++) { /* loop till we get a different start point */ - while ((rnd2 = random() % num_starts) == rnd) + while ((rnd2 = atcrandom() % num_starts) == rnd) ; if (rnd2 < sp->num_exits) { p.orig_type = T_EXIT; -- cgit v1.2.3