summaryrefslogtreecommitdiff
path: root/source/base/base_rand.h
blob: 5a8668c7ae6ec07b3553cfbba6588f2bb4fca1fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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_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