diff options
author | June McEnroe <june@causal.agency> | 2019-03-24 01:28:23 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-03-24 01:28:23 -0400 |
commit | a05e65a048db96d0e86e216e4d7be94e74aba375 (patch) | |
tree | 5d5c882fd49c07a392621eda80d74fa700a4a6ae /stack.h | |
parent | Search pref path, base path for CARDS.DLL, SOL.EXE (diff) | |
download | cards-a05e65a048db96d0e86e216e4d7be94e74aba375.tar.gz cards-a05e65a048db96d0e86e216e4d7be94e74aba375.zip |
Use rand(3)
Disgusting, I know. randUniform is based on the FreeBSD implementation of arc4random_uniform(3).
Diffstat (limited to 'stack.h')
-rw-r--r-- | stack.h | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/stack.h b/stack.h index a635e8c..4daf6ba 100644 --- a/stack.h +++ b/stack.h @@ -90,10 +90,16 @@ static inline void stackDeck(struct Stack *stack) { } } -// FIXME: Use a portable random. +static inline int randUniform(int bound) { + for (;;) { + int r = rand(); + if (r >= RAND_MAX % bound) return r % bound; + } +} + static inline void stackShuffle(struct Stack *stack) { for (Uint8 i = stack->len - 1; i > 0; --i) { - Uint8 j = arc4random_uniform(i + 1); + Uint8 j = randUniform(i + 1); Sint8 x = stack->cards[i]; stack->cards[i] = stack->cards[j]; stack->cards[j] = x; |