From ab32d51871248e0fbf6758a425eda2256712d519 Mon Sep 17 00:00:00 2001 From: citrons Date: Wed, 11 Oct 2023 23:58:12 -0500 Subject: initial commit --- random.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 random.c (limited to 'random.c') diff --git a/random.c b/random.c new file mode 100644 index 0000000..c53d378 --- /dev/null +++ b/random.c @@ -0,0 +1,26 @@ +#include + +static Uint64 random = 0xbee; + +void seed_rand(Uint64 seed) { + random ^= seed; +} + +Uint64 get_rand() { + random ^= random >> 7; + random ^= random << 9; + random ^= random >> 13; + return random; +} + +int rand_int() { + Uint64 rand = get_rand(); + int result; + memcpy(&result, &rand, sizeof(int)); + result = SDL_abs(result); + return result; +} + +double rand_float() { + return (get_rand() >> 11) * 0x1.0p-53; +} -- cgit v1.2.3