SDL: Moved SDL_rand auto-initialization out of SDL_rand_r

From f4ee59a1a26b12fba4ba3e44f615af22c54d7538 Mon Sep 17 00:00:00 2001
From: John Kaniarz <[EMAIL REDACTED]>
Date: Sun, 16 Jun 2024 20:25:47 -0400
Subject: [PATCH] Moved SDL_rand auto-initialization out of SDL_rand_r

---
 src/stdlib/SDL_random.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/stdlib/SDL_random.c b/src/stdlib/SDL_random.c
index 0102a7a088298..4ac7401a91f8b 100644
--- a/src/stdlib/SDL_random.c
+++ b/src/stdlib/SDL_random.c
@@ -23,15 +23,23 @@
 /* This file contains portable random functions for SDL */
 
 static Uint64 SDL_rand_state;
+static SDL_bool SDL_rand_initialized = SDL_FALSE;
 
 void SDL_srand(Uint64 seed)
 {
+    if (!seed) {
+        seed = SDL_GetPerformanceCounter();
+    }
     SDL_rand_state = seed;
+    SDL_rand_initialized = SDL_TRUE;
 }
 
 Uint32 SDL_rand(void)
 {
-	return SDL_rand_r(&SDL_rand_state);
+    if(!SDL_rand_initialized) {
+        SDL_srand(0);
+    }
+    return SDL_rand_r(&SDL_rand_state);
 }
 
 /*
@@ -62,10 +70,6 @@ Uint32 SDL_rand_r(Uint64 *state)
         return 0;
     }
 
-    if (!*state) {
-        *state = SDL_GetPerformanceCounter();
-    }
-
 	// Multiplier from Table 6 of
 	// Steele GL, Vigna S. Computationally easy, spectrally good multipliers
 	// for congruential pseudorandom number generators.