aboutsummaryrefslogtreecommitdiff
path: root/src/base/rng/base.c
blob: 9ec496ea40f5fc9475a33b0e16bdec4109940931 (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
#include "internal.h"

static uint64
splitmix64(struct Mix *state)
{
    uint64 result = state->s;

    state->s = result + 0x9E3779B97f4A7C15;
    result = (result ^ (result >> 30)) * 0xBF58476D1CE4E5B9;
    result = (result ^ (result >> 27)) * 0x94D049BB133111EB;
    return result ^ (result >> 31);
}

int
rng·init(uint64 seed)
{
    int i;
    Mix smstate = {seed};

    for(i=0; i < 4; i++)
        rng·RNG.s[i] = splitmix64(&smstate);

    return 0;
}