From 8ea6a3c8621287d11296b8300029f32a27743d9a Mon Sep 17 00:00:00 2001 From: nasr Date: Thu, 16 Apr 2026 17:10:02 +0200 Subject: feature(checkpoint): checkpoint cleaning up base library --- source/base/base_rand.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 source/base/base_rand.h (limited to 'source/base/base_rand.h') diff --git a/source/base/base_rand.h b/source/base/base_rand.h new file mode 100644 index 0000000..86acafe --- /dev/null +++ b/source/base/base_rand.h @@ -0,0 +1,29 @@ +#ifndef BASE_RAND_H +#define BASE_RAND_H + +// source: https://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64 + +#define RAND_CONSTANT 6364136223846793005 +#define GEN_RAND() _generate_random_u64(RAND_CONSTANT) + +#endif /* BASE_RAND_H */ + +#ifdef BASE_RAND_IMPLEMENTATION +internal u64 +generate_random_u64(u64 constant) +{ + + time_t current_time = time(NULL); + return current_time ^ constant; + + constant += 0x9e3779b97f4a7c15; + + u64 z = constant; + z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; + z = (z ^ (z >> 27)) * 0x94d049bb133111eb; + z = z ^ (z >> 31); + + return z; +} + +#endif -- cgit v1.3