Files
GeneticAlgo/inc/rand.h

19 lines
473 B
C++

// TODO: This file needs a serious audit
#include <cstdint>
constexpr uint64_t half_max = UINT64_MAX / 2;
// From https://en.wikipedia.org/wiki/Xorshift
inline void xorshift64(uint64_t &state) {
state ^= state << 13;
state ^= state >> 7;
state ^= state << 17;
}
// returns a random value between -1 and 1. modifies seed
inline float norm_rand(uint64_t &state) {
xorshift64(state);
return static_cast<float>(state - half_max) / static_cast<float>(half_max);
}