diff options
author | tb <tb@cvs.openbsd.org> | 2015-12-15 18:39:51 +0000 |
---|---|---|
committer | tb <tb@cvs.openbsd.org> | 2015-12-15 18:39:51 +0000 |
commit | 8236da4262b9c466095ac54cef7f1ae9e195c371 (patch) | |
tree | e938fbbb9fab8e695715c19bd373a48819992544 /games/atc/update.c | |
parent | 4211379094e51be9238f6a684178ea2564993be7 (diff) |
Replace 'arc4random() % range' by 'arc4random_uniform(range)'.
Do this by introducing atcrandom_uniform(range) which returns
deterministic randomness or good randomness depending on whether
a seed was specified with the -r option.
Diff by Matthew Martin, reviewed by deraadt@ and me.
ok deraadt@
Diffstat (limited to 'games/atc/update.c')
-rw-r--r-- | games/atc/update.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/games/atc/update.c b/games/atc/update.c index 36cf824bd27..0f172c5d737 100644 --- a/games/atc/update.c +++ b/games/atc/update.c @@ -1,4 +1,4 @@ -/* $OpenBSD: update.c,v 1.16 2014/12/09 05:01:14 deraadt Exp $ */ +/* $OpenBSD: update.c,v 1.17 2015/12/15 18:39:50 tb Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -59,6 +59,15 @@ atcrandom() return arc4random(); } +uint32_t +atcrandom_uniform(uint32_t upper_bound) +{ + if (seeded) + return random() % upper_bound; + else + return arc4random_uniform(upper_bound); +} + void update(int dummy) { @@ -212,7 +221,7 @@ update(int dummy) * Otherwise, prop jobs show up *on* entrance. Remember that * we don't update props on odd updates. */ - if ((atcrandom() % sp->newplane_time) == 0) + if (atcrandom_uniform(sp->newplane_time) == 0) addplane(); } @@ -308,10 +317,10 @@ addplane(void) memset(&p, 0, sizeof (p)); p.status = S_MARKED; - p.plane_type = atcrandom() % 2; + p.plane_type = atcrandom_uniform(2); num_starts = sp->num_exits + sp->num_airports; - rnd = atcrandom() % num_starts; + rnd = atcrandom_uniform(num_starts); if (rnd < sp->num_exits) { p.dest_type = T_EXIT; @@ -324,7 +333,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 = atcrandom() % num_starts) == rnd) + while ((rnd2 = atcrandom_uniform(num_starts)) == rnd) ; if (rnd2 < sp->num_exits) { p.orig_type = T_EXIT; |