This repository has been archived on 2022-05-21. You can view files and clone it, but cannot push or open issues or pull requests.
LEFTONE/util/chaos/xorshift.c

20 lines
417 B
C
Raw Permalink Normal View History

#include "./xorshift.h"
#include <stddef.h>
#include <stdint.h>
uint64_t chaos_xorshift(uint64_t seed) {
seed = seed ^ (seed << 13);
seed = seed ^ (seed >> 7);
return seed ^ (seed << 17);
}
float chaos_xorshift_fract(uint64_t seed, uint64_t* next_seed) {
static const uint64_t period = 10000;
seed = chaos_xorshift(seed);
if (next_seed != NULL) *next_seed = seed;
return seed%period*1.f/period;
}