src/util.c

changeset 273
966bfca56b9d
parent 266
a73674e99e62
--- a/src/util.c	Wed Aug 20 23:51:40 2025 +0200
+++ b/src/util.c	Thu Aug 21 22:13:51 2025 +0200
@@ -28,10 +28,22 @@
 #include "ascension/util.h"
 
 #include <cx/printf.h>
-#include <inttypes.h>
-#include <assert.h>
+#include <SDL3/SDL_stdinc.h>
 
 cxmutstr asc_util_gen_name(const char *prefix) {
     static unsigned counter = 0;
     return cx_asprintf("%s_gen%u", prefix, ++counter);
 }
+
+void asc_util_seed_rand(uint64_t seed) {
+    SDL_srand(seed);
+}
+
+uint32_t asc_util_rand(uint32_t n) {
+    if (n > INT32_MAX) {
+        // TODO: this probably uses quality of the generated numbers
+        return SDL_rand_bits() % n;
+    } else {
+        return SDL_rand((int32_t) n);
+    }
+}

mercurial