SDL: Replaced test framework random code with SDL random functions

From a938e2b979f66b9fa35d53ba4eb972dde9c43d10 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 23 Jun 2024 12:42:54 -0700
Subject: [PATCH] Replaced test framework random code with SDL random functions

---
 VisualC-GDK/SDL/SDL.vcxproj                   |   1 -
 VisualC-GDK/SDL/SDL.vcxproj.filters           |   1 -
 VisualC-GDK/SDL_test/SDL_test.vcxproj         |   1 -
 VisualC-WinRT/testdraw/testdraw.vcxproj       |   1 -
 .../testdraw/testdraw.vcxproj.filters         |   3 -
 VisualC/SDL/SDL.vcxproj                       |   1 -
 VisualC/SDL/SDL.vcxproj.filters               |   3 -
 VisualC/SDL_test/SDL_test.vcxproj             |   3 +-
 .../SDLTest/SDLTest.xcodeproj/project.pbxproj |   4 -
 include/SDL3/SDL_test.h                       |   1 -
 include/SDL3/SDL_test_random.h                | 112 ------------------
 src/test/SDL_test_fuzzer.c                    |  29 ++---
 src/test/SDL_test_harness.c                   |   6 +-
 src/test/SDL_test_random.c                    |  98 ---------------
 test/testqsort.c                              |  16 +--
 test/testsprite.c                             |   5 +-
 16 files changed, 21 insertions(+), 264 deletions(-)
 delete mode 100644 include/SDL3/SDL_test_random.h
 delete mode 100644 src/test/SDL_test_random.c

diff --git a/VisualC-GDK/SDL/SDL.vcxproj b/VisualC-GDK/SDL/SDL.vcxproj
index 4c0c080532988..bb7c85405bf71 100644
--- a/VisualC-GDK/SDL/SDL.vcxproj
+++ b/VisualC-GDK/SDL/SDL.vcxproj
@@ -375,7 +375,6 @@
     <ClInclude Include="..\..\include\SDL3\SDL_test_log.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_test_md5.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_test_memory.h" />
-    <ClInclude Include="..\..\include\SDL3\SDL_test_random.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_thread.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_time.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_timer.h" />
diff --git a/VisualC-GDK/SDL/SDL.vcxproj.filters b/VisualC-GDK/SDL/SDL.vcxproj.filters
index 5be93eef16972..2b4f69eb03c67 100644
--- a/VisualC-GDK/SDL/SDL.vcxproj.filters
+++ b/VisualC-GDK/SDL/SDL.vcxproj.filters
@@ -295,7 +295,6 @@
     <ClInclude Include="..\..\include\SDL3\SDL_test_log.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_test_md5.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_test_memory.h" />
-    <ClInclude Include="..\..\include\SDL3\SDL_test_random.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_thread.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_timer.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_touch.h" />
diff --git a/VisualC-GDK/SDL_test/SDL_test.vcxproj b/VisualC-GDK/SDL_test/SDL_test.vcxproj
index 2984a460998f4..2c7ada3ca0148 100644
--- a/VisualC-GDK/SDL_test/SDL_test.vcxproj
+++ b/VisualC-GDK/SDL_test/SDL_test.vcxproj
@@ -195,7 +195,6 @@
     <ClCompile Include="..\..\src\test\SDL_test_log.c" />
     <ClCompile Include="..\..\src\test\SDL_test_md5.c" />
     <ClCompile Include="..\..\src\test\SDL_test_memory.c" />
-    <ClCompile Include="..\..\src\test\SDL_test_random.c" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
diff --git a/VisualC-WinRT/testdraw/testdraw.vcxproj b/VisualC-WinRT/testdraw/testdraw.vcxproj
index f612acf98b121..eea5a6ccd31eb 100644
--- a/VisualC-WinRT/testdraw/testdraw.vcxproj
+++ b/VisualC-WinRT/testdraw/testdraw.vcxproj
@@ -294,7 +294,6 @@
     <ClCompile Include="..\..\src\test\SDL_test_log.c" />
     <ClCompile Include="..\..\src\test\SDL_test_md5.c" />
     <ClCompile Include="..\..\src\test\SDL_test_memory.c" />
-    <ClCompile Include="..\..\src\test\SDL_test_random.c" />
     <ClCompile Include="..\..\test\main.cpp">
       <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</CompileAsWinRT>
       <CompileAsWinRT Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</CompileAsWinRT>
diff --git a/VisualC-WinRT/testdraw/testdraw.vcxproj.filters b/VisualC-WinRT/testdraw/testdraw.vcxproj.filters
index d41d939d6da7c..2640e2a472ab8 100644
--- a/VisualC-WinRT/testdraw/testdraw.vcxproj.filters
+++ b/VisualC-WinRT/testdraw/testdraw.vcxproj.filters
@@ -75,9 +75,6 @@
     <ClCompile Include="..\..\src\test\SDL_test_memory.c">
       <Filter>Common</Filter>
     </ClCompile>
-    <ClCompile Include="..\..\src\test\SDL_test_random.c">
-      <Filter>Common</Filter>
-    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <None Include="..\..\src\main\winrt\SDL3-WinRTResource_BlankCursor.cur" />
diff --git a/VisualC/SDL/SDL.vcxproj b/VisualC/SDL/SDL.vcxproj
index 07f1fa70c4708..87dd7ee8ee27b 100644
--- a/VisualC/SDL/SDL.vcxproj
+++ b/VisualC/SDL/SDL.vcxproj
@@ -300,7 +300,6 @@
     <ClInclude Include="..\..\include\SDL3\SDL_test_log.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_test_md5.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_test_memory.h" />
-    <ClInclude Include="..\..\include\SDL3\SDL_test_random.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_thread.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_time.h" />
     <ClInclude Include="..\..\include\SDL3\SDL_timer.h" />
diff --git a/VisualC/SDL/SDL.vcxproj.filters b/VisualC/SDL/SDL.vcxproj.filters
index a58186a588515..4eb44ad41f30c 100644
--- a/VisualC/SDL/SDL.vcxproj.filters
+++ b/VisualC/SDL/SDL.vcxproj.filters
@@ -399,9 +399,6 @@
     <ClInclude Include="..\..\include\SDL3\SDL_test_md5.h">
       <Filter>API Headers</Filter>
     </ClInclude>
-    <ClInclude Include="..\..\include\SDL3\SDL_test_random.h">
-      <Filter>API Headers</Filter>
-    </ClInclude>
     <ClInclude Include="..\..\include\SDL3\SDL_thread.h">
       <Filter>API Headers</Filter>
     </ClInclude>
diff --git a/VisualC/SDL_test/SDL_test.vcxproj b/VisualC/SDL_test/SDL_test.vcxproj
index da264650fae17..90b52243ca199 100644
--- a/VisualC/SDL_test/SDL_test.vcxproj
+++ b/VisualC/SDL_test/SDL_test.vcxproj
@@ -163,9 +163,8 @@
     <ClCompile Include="..\..\src\test\SDL_test_log.c" />
     <ClCompile Include="..\..\src\test\SDL_test_md5.c" />
     <ClCompile Include="..\..\src\test\SDL_test_memory.c" />
-    <ClCompile Include="..\..\src\test\SDL_test_random.c" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj
index c0c1cb8a58600..e40038e4c9931 100644
--- a/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj
+++ b/Xcode/SDLTest/SDLTest.xcodeproj/project.pbxproj
@@ -116,7 +116,6 @@
 		DB166D9916A1D1A500A1396C /* SDL_test_harness.c in Sources */ = {isa = PBXBuildFile; fileRef = DB166D8A16A1D1A500A1396C /* SDL_test_harness.c */; };
 		DB166D9F16A1D1A500A1396C /* SDL_test_log.c in Sources */ = {isa = PBXBuildFile; fileRef = DB166D9016A1D1A500A1396C /* SDL_test_log.c */; };
 		DB166DA016A1D1A500A1396C /* SDL_test_md5.c in Sources */ = {isa = PBXBuildFile; fileRef = DB166D9116A1D1A500A1396C /* SDL_test_md5.c */; };
-		DB166DA116A1D1A500A1396C /* SDL_test_random.c in Sources */ = {isa = PBXBuildFile; fileRef = DB166D9216A1D1A500A1396C /* SDL_test_random.c */; };
 		DB166DD716A1D37800A1396C /* testmessage.c in Sources */ = {isa = PBXBuildFile; fileRef = DB166CBD16A1C74100A1396C /* testmessage.c */; };
 		DB166DDB16A1D42F00A1396C /* icon.bmp in CopyFiles */ = {isa = PBXBuildFile; fileRef = 00794E5D09D20839003FC8A1 /* icon.bmp */; };
 		DB166DF016A1D52500A1396C /* testrelative.c in Sources */ = {isa = PBXBuildFile; fileRef = DB166CBF16A1C74100A1396C /* testrelative.c */; };
@@ -1315,7 +1314,6 @@
 		DB166D8A16A1D1A500A1396C /* SDL_test_harness.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_test_harness.c; sourceTree = "<group>"; };
 		DB166D9016A1D1A500A1396C /* SDL_test_log.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_test_log.c; sourceTree = "<group>"; };
 		DB166D9116A1D1A500A1396C /* SDL_test_md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_test_md5.c; sourceTree = "<group>"; };
-		DB166D9216A1D1A500A1396C /* SDL_test_random.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_test_random.c; sourceTree = "<group>"; };
 		DB166DD516A1D36A00A1396C /* testmessage.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testmessage.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		DB166DEE16A1D50C00A1396C /* testrelative.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testrelative.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		DB166E0516A1D57C00A1396C /* testrendercopyex.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testrendercopyex.app; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -1935,7 +1933,6 @@
 				DB166D9016A1D1A500A1396C /* SDL_test_log.c */,
 				DB166D9116A1D1A500A1396C /* SDL_test_md5.c */,
 				AAF02FF41F90089800B9A9FB /* SDL_test_memory.c */,
-				DB166D9216A1D1A500A1396C /* SDL_test_random.c */,
 			);
 			name = SDL_Test;
 			path = ../../src/test;
@@ -3308,7 +3305,6 @@
 				DB166D9F16A1D1A500A1396C /* SDL_test_log.c in Sources */,
 				DB166DA016A1D1A500A1396C /* SDL_test_md5.c in Sources */,
 				AAF02FFA1F90092700B9A9FB /* SDL_test_memory.c in Sources */,
-				DB166DA116A1D1A500A1396C /* SDL_test_random.c in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/include/SDL3/SDL_test.h b/include/SDL3/SDL_test.h
index 634382cf41cdd..e8468739136de 100644
--- a/include/SDL3/SDL_test.h
+++ b/include/SDL3/SDL_test.h
@@ -41,7 +41,6 @@
 #include <SDL3/SDL_test_log.h>
 #include <SDL3/SDL_test_md5.h>
 #include <SDL3/SDL_test_memory.h>
-#include <SDL3/SDL_test_random.h>
 
 #include <SDL3/SDL_begin_code.h>
 /* Set up for C function definitions, even when using C++ */
diff --git a/include/SDL3/SDL_test_random.h b/include/SDL3/SDL_test_random.h
deleted file mode 100644
index 73088e138fdcc..0000000000000
--- a/include/SDL3/SDL_test_random.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
-  Simple DirectMedia Layer
-  Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-*/
-
-/**
- *  \file SDL_test_random.h
- *
- *  Random number generator related function of SDL test framework.
- *
- *  This code is a part of the SDL test library, not the main SDL library.
- */
-
-/*
-
- A "32-bit Multiply with carry random number generator. Very fast.
- Includes a list of recommended multipliers.
-
- multiply-with-carry generator: x(n) = a*x(n-1) + carry mod 2^32.
- period: (a*2^31)-1
-
-*/
-
-#ifndef SDL_test_random_h_
-#define SDL_test_random_h_
-
-#include <SDL3/SDL_begin_code.h>
-/* Set up for C function definitions, even when using C++ */
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* --- Definitions */
-
-/*
- * Macros that return a random number in a specific format.
- */
-#define SDLTest_RandomInt(c)        ((int)SDLTest_Random(c))
-
-/*
- * Context structure for the random number generator state.
- */
-  typedef struct SDLTest_RandomContext {
-    unsigned int a;
-    unsigned int x;
-    unsigned int c;
-    unsigned int ah;
-    unsigned int al;
-  } SDLTest_RandomContext;
-
-
-/* --- Function prototypes */
-
-/**
- *  Initialize random number generator with two integers.
- *
- *  Note: The random sequence of numbers returned by ...Random() is the
- *  same for the same two integers and has a period of 2^31.
- *
- *  \param rndContext     pointer to context structure
- *  \param xi         integer that defines the random sequence
- *  \param ci         integer that defines the random sequence
- *
- */
- void SDLTest_RandomInit(SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci);
-
-/**
- *  Initialize random number generator based on current system time.
- *
- *  \param rndContext     pointer to context structure
- *
- */
- void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext);
-
-
-/**
- *  Initialize random number generator based on current system time.
- *
- *  Note: ...RandomInit() or ...RandomInitTime() must have been called
- *  before using this function.
- *
- *  \param rndContext     pointer to context structure
- *
- *  \returns a random number (32bit unsigned integer)
- *
- */
- unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext);
-
-
-/* Ends C function definitions when using C++ */
-#ifdef __cplusplus
-}
-#endif
-#include <SDL3/SDL_close_code.h>
-
-#endif /* SDL_test_random_h_ */
diff --git a/src/test/SDL_test_fuzzer.c b/src/test/SDL_test_fuzzer.c
index 7e45f6c0e603a..73fc07f1e36c6 100644
--- a/src/test/SDL_test_fuzzer.c
+++ b/src/test/SDL_test_fuzzer.c
@@ -37,7 +37,7 @@ static int fuzzerInvocationCounter = 0;
 /**
  * Context for shared random number generator
  */
-static SDLTest_RandomContext rndContext;
+static Uint64 rndContext;
 
 /*
  * Note: doxygen documentation markup for functions is in the header file.
@@ -45,10 +45,7 @@ static SDLTest_RandomContext rndContext;
 
 void SDLTest_FuzzerInit(Uint64 execKey)
 {
-    Uint32 a = (execKey >> 32) & 0x00000000FFFFFFFF;
-    Uint32 b = execKey & 0x00000000FFFFFFFF;
-    SDL_memset((void *)&rndContext, 0, sizeof(SDLTest_RandomContext));
-    SDLTest_RandomInit(&rndContext, a, b);
+    rndContext = execKey;
     fuzzerInvocationCounter = 0;
 }
 
@@ -61,42 +58,42 @@ Uint8 SDLTest_RandomUint8(void)
 {
     fuzzerInvocationCounter++;
 
-    return (Uint8)SDLTest_RandomInt(&rndContext) & 0x000000FF;
+    return (Uint8)SDL_rand_r(&rndContext, SDL_MAX_UINT8 + 1);
 }
 
 Sint8 SDLTest_RandomSint8(void)
 {
     fuzzerInvocationCounter++;
 
-    return (Sint8)SDLTest_RandomInt(&rndContext) & 0x000000FF;
+    return (Sint8)SDL_rand_r(&rndContext, SDL_MAX_UINT8 + 1) ;
 }
 
 Uint16 SDLTest_RandomUint16(void)
 {
     fuzzerInvocationCounter++;
 
-    return (Uint16)SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
+    return (Uint16)SDL_rand_r(&rndContext, SDL_MAX_UINT16 + 1);
 }
 
 Sint16 SDLTest_RandomSint16(void)
 {
     fuzzerInvocationCounter++;
 
-    return (Sint16)SDLTest_RandomInt(&rndContext) & 0x0000FFFF;
+    return (Sint16)SDL_rand_r(&rndContext, SDL_MAX_UINT16 + 1);
 }
 
 Sint32 SDLTest_RandomSint32(void)
 {
     fuzzerInvocationCounter++;
 
-    return (Sint32)SDLTest_RandomInt(&rndContext);
+    return (Sint32)SDL_rand_bits_r(&rndContext);
 }
 
 Uint32 SDLTest_RandomUint32(void)
 {
     fuzzerInvocationCounter++;
 
-    return (Uint32)SDLTest_RandomInt(&rndContext);
+    return (Uint32)SDL_rand_bits_r(&rndContext);
 }
 
 Uint64 SDLTest_RandomUint64(void)
@@ -110,8 +107,8 @@ Uint64 SDLTest_RandomUint64(void)
 
     fuzzerInvocationCounter++;
 
-    value.v32[0] = SDLTest_RandomSint32();
-    value.v32[1] = SDLTest_RandomSint32();
+    value.v32[0] = SDLTest_RandomUint32();
+    value.v32[1] = SDLTest_RandomUint32();
 
     return value.v64;
 }
@@ -127,8 +124,8 @@ Sint64 SDLTest_RandomSint64(void)
 
     fuzzerInvocationCounter++;
 
-    value.v32[0] = SDLTest_RandomSint32();
-    value.v32[1] = SDLTest_RandomSint32();
+    value.v32[0] = SDLTest_RandomUint32();
+    value.v32[1] = SDLTest_RandomUint32();
 
     return (Sint64)value.v64;
 }
@@ -432,7 +429,7 @@ SDLTest_RandomDouble(void)
     double s = 1.0;
     do {
         s /= UINT_MAX + 1.0;
-        r += (double)SDLTest_RandomInt(&rndContext) * s;
+        r += (double)SDLTest_RandomSint32() * s;
     } while (s > DBL_EPSILON);
 
     fuzzerInvocationCounter++;
diff --git a/src/test/SDL_test_harness.c b/src/test/SDL_test_harness.c
index fd46e8f140525..674d125de0df7 100644
--- a/src/test/SDL_test_harness.c
+++ b/src/test/SDL_test_harness.c
@@ -63,7 +63,7 @@ static Uint32 SDLTest_TestCaseTimeout = 3600;
 char *SDLTest_GenerateRunSeed(const int length)
 {
     char *seed = NULL;
-    SDLTest_RandomContext randomContext;
+    Uint64 randomContext = SDL_GetPerformanceCounter();
     int counter;
 
     /* Sanity check input */
@@ -80,10 +80,8 @@ char *SDLTest_GenerateRunSeed(const int length)
     }
 
     /* Generate a random string of alphanumeric characters */
-    SDLTest_RandomInitTime(&randomContext);
     for (counter = 0; counter < length; counter++) {
-        unsigned int number = SDLTest_Random(&randomContext);
-        char ch = (char)(number % (91 - 48)) + 48;
+        char ch = (char)(SDL_rand_r(&randomContext, (91 - 48) + 1) + 48);
         if (ch >= 58 && ch <= 64) {
             ch = 65;
         }
diff --git a/src/test/SDL_test_random.c b/src/test/SDL_test_random.c
deleted file mode 100644
index 679ef7ee00d3c..0000000000000
--- a/src/test/SDL_test_random.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-  Simple DirectMedia Layer
-  Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
-
-  This software is provided 'as-is', without any express or implied
-  warranty.  In no event will the authors be held liable for any damages
-  arising from the use of this software.
-
-  Permission is granted to anyone to use this software for any purpose,
-  including commercial applications, and to alter it and redistribute it
-  freely, subject to the following restrictions:
-
-  1. The origin of this software must not be misrepresented; you must not
-     claim that you wrote the original software. If you use this software
-     in a product, an acknowledgment in the product documentation would be
-     appreciated but is not required.
-  2. Altered source versions must be plainly marked as such, and must not be
-     misrepresented as being the original software.
-  3. This notice may not be removed or altered from any source distribution.
-*/
-
-/*
-
- A portable "32-bit Multiply with carry" random number generator.
-
- Used by the fuzzer component.
- Original source code contributed by A. Schiffler for GSOC project.
-
-*/
-#include <SDL3/SDL_test.h>
-
-#include <stdlib.h> /* Needed for srand() and rand() */
-#include <time.h>   /* Needed for time() */
-
-/* Initialize random number generator with two integer variables */
-
-void SDLTest_RandomInit(SDLTest_RandomContext *rndContext, unsigned int xi, unsigned int ci)
-{
-    if (!rndContext) {
-        return;
-    }
-
-    /*
-     * Choose a value for 'a' from this list
-     * 1791398085 1929682203 1683268614 1965537969 1675393560
-     * 1967773755 1517746329 1447497129 1655692410 1606218150
-     * 2051013963 1075433238 1557985959 1781943330 1893513180
-     * 1631296680 2131995753 2083801278 1873196400 1554115554
-     */
-    rndContext->a = 1655692410;
-    rndContext->x = 30903;
-    rndContext->c = 0;
-    if (xi != 0) {
-        rndContext->x = xi;
-    }
-    rndContext->c = ci;
-    rndContext->ah = rndContext->a >> 16;
-    rndContext->al = rndContext->a & 65535;
-}
-
-/* Initialize random number generator from system time */
-
-void SDLTest_RandomInitTime(SDLTest_RandomContext *rndContext)
-{
-    int a, b;
-
-    if (!rndContext) {
-        return;
-    }
-
-    srand((unsigned int)time(NULL));
-    a = rand();
-    srand((unsigned int)SDL_GetPerformanceCounter());
-    b = rand();
-    SDLTest_RandomInit(rndContext, a, b);
-}
-
-/* Returns random numbers */
-
-unsigned int SDLTest_Random(SDLTest_RandomContext *rndContext)
-{
-    unsigned int xh, xl;
-
-    if (!rndContext) {
-        return 0;
-    }
-
-    xh = rndContext->x >> 16;
-    xl = rndContext->x & 65535;
-    rndContext->x = rndContext->x * rndContext->a + rndContext->c;
-    rndContext->c =
-        xh * rndContext->ah + ((xh * rndContext->al) >> 16) +
-        ((xl * rndContext->ah) >> 16);
-    if (xl * rndContext->al >= (~rndContext->c + 1)) {
-        rndContext->c++;
-    }
-    return rndContext->x;
-}
diff --git a/test/testqsort.c b/test/testqsort.c
index 5fa5db7b8c96a..5b8eb5b2f4c26 100644
--- a/test/testqsort.c
+++ b/test/testqsort.c
@@ -67,12 +67,10 @@ int main(int argc, char *argv[])
     static const int itervals[] = { SDL_arraysize(nums), 12 };
     int i;
     int iteration;
-    SDLTest_RandomContext rndctx;
     SDLTest_CommonState *state;
+    Uint64 seed = 0;
     int seed_seen = 0;
 
-    SDL_zero(rndctx);
-
     /* Initialize test framework */
     state = SDLTest_CommonCreateState(argv, 0);
     if (!state) {
@@ -86,7 +84,6 @@ int main(int argc, char *argv[])
         consumed = SDLTest_CommonArg(state, i);
         if (!consumed) {
             if (!seed_seen) {
-                Uint64 seed = 0;
                 char *endptr = NULL;
 
                 seed = SDL_strtoull(argv[i], &endptr, 0);
@@ -97,11 +94,6 @@ int main(int argc, char *argv[])
                     SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Invalid seed. Use a decimal or hexadecimal number.\n");
                     return 1;
                 }
-                if (seed <= ((Uint64)0xffffffff)) {
-                    SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Seed must be equal or greater than 0x100000000.\n");
-                    return 1;
-                }
-                SDLTest_RandomInit(&rndctx, (unsigned int)(seed >> 32), (unsigned int)(seed & 0xffffffff));
             }
         }
         if (consumed <= 0) {
@@ -114,9 +106,9 @@ int main(int argc, char *argv[])
     }
 
     if (!seed_seen) {
-        SDLTest_RandomInitTime(&rndctx);
+        seed = SDL_GetPerformanceCounter();
     }
-    SDL_Log("Using random seed 0x%08x%08x\n", rndctx.x, rndctx.c);
+    SDL_Log("Using random seed 0x%" SDL_PRIx64 "\n", seed);
 
     for (iteration = 0; iteration < SDL_arraysize(itervals); iteration++) {
         const int arraylen = itervals[iteration];
@@ -138,7 +130,7 @@ int main(int argc, char *argv[])
         test_sort("reverse sorted", nums, arraylen);
 
         for (i = 0; i < arraylen; i++) {
-            nums[i] = SDLTest_RandomInt(&rndctx);
+            nums[i] = SDL_rand_r(&seed, SDL_MAX_SINT32);
         }
         test_sort("random sorted", nums, arraylen);
     }
diff --git a/test/testsprite.c b/test/testsprite.c
index a9e8888a7dd6c..8fb3531d62ac3 100644
--- a/test/testsprite.c
+++ b/test/testsprite.c
@@ -11,9 +11,6 @@
 */
 /* Simple program:  Move N sprites around on the screen as fast as possible */
 
-#include <stdlib.h>
-#include <time.h>
-
 #define SDL_MAIN_USE_CALLBACKS 1
 #include <SDL3/SDL_test.h>
 #include <SDL3/SDL_test_common.h>
@@ -558,7 +555,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
         seed = (Uint64)iterations;
     } else {
         /* Pseudo-random seed generated from the time */
-        seed = (Uint64)time(NULL);
+        seed = SDL_GetPerformanceCounter();
     }
     SDLTest_FuzzerInit(seed);
     for (i = 0; i < num_sprites; ++i) {