diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-11-03 22:18:16 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-11-03 22:18:16 +0000 |
commit | 81b3b0d6cfb351a857af750e1e33fb3dd4e163f4 (patch) | |
tree | 268ff1cacd97fe835a0a395fdb16fd02b6c7c568 /games | |
parent | d4a890403045bdf851142b08e767b9b3a32757c1 (diff) |
use knuth shuffle for better distribution of permutations
Diffstat (limited to 'games')
-rw-r--r-- | games/mille/init.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/games/mille/init.c b/games/mille/init.c index 87a6e0bc813..20aeb99e2fb 100644 --- a/games/mille/init.c +++ b/games/mille/init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: init.c,v 1.6 2009/10/27 23:59:25 deraadt Exp $ */ +/* $OpenBSD: init.c,v 1.7 2014/11/03 22:18:15 tedu Exp $ */ /* $NetBSD: init.c,v 1.5 1995/03/24 05:01:40 cgd Exp $ */ /* @@ -86,12 +86,8 @@ shuffle() int i, r; CARD temp; - for (i = 0; i < DECK_SZ; i++) { - r = roll(1, DECK_SZ) - 1; - if (r < 0 || r > DECK_SZ - 1) { - warnx("shuffle: card no. error: %d", r); - die(1); - } + for (i = DECK_SZ - 1; i > 0; i--) { + r = arc4random_uniform(i + 1); temp = Deck[r]; Deck[r] = Deck[i]; Deck[i] = temp; |