summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2013-10-25 18:31:30 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2013-10-25 18:31:30 +0000
commitbb06724b2414d97347ebf92bab492db33bdaeea7 (patch)
treec9d6febcc4cf3f4f22d1e9cf003f0741064496ef
parent41a1e3dc595a5b7b5f0166f0ddc7ea31238314d0 (diff)
Use arc4random_uniform() insead of rand() and modulus.
OK deraadt@
-rw-r--r--games/cribbage/cards.c7
-rw-r--r--games/cribbage/crib.c10
2 files changed, 7 insertions, 10 deletions
diff --git a/games/cribbage/cards.c b/games/cribbage/cards.c
index f27a4febdcd..26aae894600 100644
--- a/games/cribbage/cards.c
+++ b/games/cribbage/cards.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cards.c,v 1.5 2009/10/27 23:59:24 deraadt Exp $ */
+/* $OpenBSD: cards.c,v 1.6 2013/10/25 18:31:29 millert Exp $ */
/* $NetBSD: cards.c,v 1.3 1995/03/21 15:08:41 cgd Exp $ */
/*-
@@ -47,9 +47,6 @@ makedeck(CARD d[])
{
int i, j, k;
- i = time(NULL);
- i = ((i & 0xff) << 8) | ((i >> 8) & 0xff) | 1;
- srand(i);
k = 0;
for (i = 0; i < RANKS; i++)
for (j = 0; j < SUITS; j++) {
@@ -69,7 +66,7 @@ shuffle(CARD d[])
CARD c;
for (j = CARDS; j > 0; --j) {
- k = (rand() >> 4) % j; /* random 0 <= k < j */
+ k = arc4random_uniform(j); /* random 0 <= k < j */
c = d[j - 1]; /* exchange (j - 1) and k */
d[j - 1] = d[k];
d[k] = c;
diff --git a/games/cribbage/crib.c b/games/cribbage/crib.c
index b6d9970d706..7503fabf33f 100644
--- a/games/cribbage/crib.c
+++ b/games/cribbage/crib.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: crib.c,v 1.16 2012/03/04 04:05:15 fgsch Exp $ */
+/* $OpenBSD: crib.c,v 1.17 2013/10/25 18:31:29 millert Exp $ */
/* $NetBSD: crib.c,v 1.7 1997/07/10 06:47:29 mikel Exp $ */
/*-
@@ -214,9 +214,9 @@ game(void)
*foo = '\0';
} while (*foo != '\0');
}
- i = (rand() >> 4) % CARDS; /* random cut */
+ i = arc4random_uniform(CARDS); /* random cut */
do { /* comp cuts deck */
- j = (rand() >> 4) % CARDS;
+ j = arc4random_uniform(CARDS);
} while (j == i);
addmsg(quiet ? "You cut " : "You cut the ");
msgcard(deck[i], FALSE);
@@ -396,7 +396,7 @@ cut(bool mycrib, int pos)
*foo = '\0';
} while (*foo != '\0');
}
- i = (rand() >> 4) % (CARDS - pos);
+ i = arc4random_uniform(CARDS - pos);
turnover = deck[i + pos];
addmsg(quiet ? "You cut " : "You cut the ");
msgcard(turnover, FALSE);
@@ -407,7 +407,7 @@ cut(bool mycrib, int pos)
win = chkscr(&cscore, 2);
}
} else {
- i = (rand() >> 4) % (CARDS - pos) + pos;
+ i = arc4random_uniform(CARDS - pos) + pos;
turnover = deck[i];
addmsg(quiet ? "I cut " : "I cut the ");
msgcard(turnover, FALSE);