From: tedu Date: Sun, 13 Jul 2014 14:01:04 +0000 (+0000) Subject: if not seeded explicitly, use arc4random instead. ok deraadt X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=5b92e02df29f0ef5f18a1ae96205fdf96044b450;p=openbsd if not seeded explicitly, use arc4random instead. ok deraadt --- 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;