summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--sol.c1
-rw-r--r--stack.h10
2 files changed, 9 insertions, 2 deletions
diff --git a/sol.c b/sol.c
index 3aba0c5..6f6f434 100644
--- a/sol.c
+++ b/sol.c
@@ -429,6 +429,7 @@ int main(void) {
 	}
 	Cards_Free(cards);
 
+	srand(time(NULL));
 	gameDeal();
 
 	for (;;) {
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;