mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
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@
This commit is contained in:
parent
d531158ff9
commit
54a07f1471
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user