summaryrefslogtreecommitdiff
path: root/source/base/base_rand.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/base/base_rand.h')
-rw-r--r--source/base/base_rand.h29
1 files changed, 29 insertions, 0 deletions
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 @@
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
12internal u64
13generate_random_u64(u64 constant)
14{
15
16 time_t current_time = time(NULL);
17 return current_time ^ constant;
18
19 constant += 0x9e3779b97f4a7c15;
20
21 u64 z = constant;
22 z = (z ^ (z >> 30)) * 0xbf58476d1ce4e5b9;
23 z = (z ^ (z >> 27)) * 0x94d049bb133111eb;
24 z = z ^ (z >> 31);
25
26 return z;
27}
28
29#endif