summaryrefslogtreecommitdiff
path: root/lichen.c
blob: f20c1b38c0d4d7a7b992323fae9a6fc19ebd7ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "lichen.h"


void li_xorshift32_seed(struct li_xorshift32_t *xor, uint32_t seed) {
  xor->state = seed ? seed : 1;
  xor->generator.rand = li_xorshift32;
  xor->generator.state = &(xor->state);
}


uint32_t li_xorshift32(void *s) {
  uint64_t x = *((uint64_t*)s);
  x ^= x >> 12;
  x ^= x << 25;
  x ^= x >> 27;
  x *= 0x2545F4914F6CDD1DULL;
  *((uint64_t*)s) = x;
  // return just top 32 bits
  return x >> 32;
}