src/util.c

changeset 273
966bfca56b9d
parent 266
a73674e99e62
equal deleted inserted replaced
272:6ed9fb9662c0 273:966bfca56b9d
26 */ 26 */
27 27
28 #include "ascension/util.h" 28 #include "ascension/util.h"
29 29
30 #include <cx/printf.h> 30 #include <cx/printf.h>
31 #include <inttypes.h> 31 #include <SDL3/SDL_stdinc.h>
32 #include <assert.h>
33 32
34 cxmutstr asc_util_gen_name(const char *prefix) { 33 cxmutstr asc_util_gen_name(const char *prefix) {
35 static unsigned counter = 0; 34 static unsigned counter = 0;
36 return cx_asprintf("%s_gen%u", prefix, ++counter); 35 return cx_asprintf("%s_gen%u", prefix, ++counter);
37 } 36 }
37
38 void asc_util_seed_rand(uint64_t seed) {
39 SDL_srand(seed);
40 }
41
42 uint32_t asc_util_rand(uint32_t n) {
43 if (n > INT32_MAX) {
44 // TODO: this probably uses quality of the generated numbers
45 return SDL_rand_bits() % n;
46 } else {
47 return SDL_rand((int32_t) n);
48 }
49 }

mercurial