diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-07-13 14:01:05 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-07-13 14:01:05 +0000 |
commit | f42126e4a69216894f2476f998079c17944a8562 (patch) | |
tree | 116d476e8f3b4d5cd59c10314420f3faad793835 /games/atc/update.c | |
parent | 7ea78b3ecab4a806cbb9c4bda2db7d1ea8a22ea9 (diff) |
if not seeded explicitly, use arc4random instead. ok deraadt
Diffstat (limited to 'games/atc/update.c')
-rw-r--r-- | games/atc/update.c | 27 |
1 files changed, 22 insertions, 5 deletions
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; |