diff options
| author | nasr <nsrddyn@gmail.com> | 2026-04-17 17:49:10 +0200 |
|---|---|---|
| committer | nasr <nsrddyn@gmail.com> | 2026-04-17 17:50:28 +0200 |
| commit | 078e21a1feb811f9ef7797ce3ee5d2e8ffcccfce (patch) | |
| tree | c1121bed141fb536be6b21a6fc54ccd2b5ac7302 /source/base/base_rand.h | |
| parent | 9d09d66a273f68fae7efb71504bf40c664b91983 (diff) | |
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 <nsrddyn@gmail.com>
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 <nsrddyn@gmail.com>
Diffstat (limited to 'source/base/base_rand.h')
| -rw-r--r-- | source/base/base_rand.h | 28 |
1 files changed, 28 insertions, 0 deletions
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 @@ | |||
| 1 | #ifndef BASE_RAND_H | ||
| 2 | #define BASE_RAND_H | ||
| 3 | |||
| 4 | // source: https://rosettacode.org/wiki/Pseudo-random_numbers/Splitmix64 | ||
| 5 | |||
| 6 | #define RAND_CONSTANT 6364136223846793005 | ||
| 7 | #define GEN_RAND() _generate_random_u64(RAND_CONSTANT) | ||
| 8 | |||
| 9 | #endif /* BASE_RAND_H */ | ||
| 10 | |||
| 11 | #ifdef BASE_RAND_IMPLEMENTATION | ||
| 12 | internal u64 | ||
| 13 | generate_random_u64(u64 constant) | ||
| 14 | { | ||
| 15 | time_t current_time = time(0); | ||
| 16 | constant = current_time ^ constant; | ||
| 17 | |||
| 18 | constant += 0x9e3779b97f4a7c15; | ||
| 19 | |||
| 20 | u64 z = constant; | ||
| 21 | z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9; | ||
| 22 | z = (z ^ (z >> 27)) * 0x94d049bb133111eb; | ||
| 23 | z = z ^ (z >> 31); | ||
| 24 | |||
| 25 | return z; | ||
| 26 | } | ||
| 27 | |||
| 28 | #endif | ||
