From 50793e214c05ff77636addb319ccf0de864713e4 Mon Sep 17 00:00:00 2001 From: sanine Date: Fri, 24 Oct 2025 12:07:38 -0500 Subject: implement xorshift --- lichen.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lichen.c (limited to 'lichen.c') diff --git a/lichen.c b/lichen.c new file mode 100644 index 0000000..f20c1b3 --- /dev/null +++ b/lichen.c @@ -0,0 +1,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; +} -- cgit v1.2.1