From 078e21a1feb811f9ef7797ce3ee5d2e8ffcccfce Mon Sep 17 00:00:00 2001 From: nasr Date: Fri, 17 Apr 2026 17:49:10 +0200 Subject: feature(main): during my work on other projects I improved the base library a bit. this is a drag and drop of that in the project. the next steps exit out of implementing lineair regression and attempting to calcualte what the value would be of a key in the btree... Signed-off-by: nasr feature(main): during my work on other projects I improved the base library a bit. this is a drag and drop of that in the project. the next steps exit out of implementing lineair regression and attempting to calcualte what the value would be of a key in the btree... Signed-off-by: nasr --- source/base/base_rand.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 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..bfdab0f --- /dev/null +++ b/source/base/base_rand.h @@ -0,0 +1,28 @@ +#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(0); + constant = 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