diff options
| author | sanine <sanine.not@pm.me> | 2025-10-24 12:07:38 -0500 | 
|---|---|---|
| committer | sanine <sanine.not@pm.me> | 2025-10-24 12:07:38 -0500 | 
| commit | 50793e214c05ff77636addb319ccf0de864713e4 (patch) | |
| tree | 21e6642ded86528b54fc530f9a5ec337a5900dcb /lichen.c | |
| parent | 6547ddfe210f06ab584a6781a06b9c844b6eaf7c (diff) | |
implement xorshift
Diffstat (limited to 'lichen.c')
| -rw-r--r-- | lichen.c | 20 | 
1 files changed, 20 insertions, 0 deletions
| 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; +} | 
