]> git.localhorst.tv Git - blank.git/blobdiff - src/noise.cpp
added Galois LFSR PRNG
[blank.git] / src / noise.cpp
index c86f833ac3c126c894a53eeb5ad6df6c9c835d02..6d59224c2f41f4de89ae982627387fcacd7235a2 100644 (file)
@@ -12,6 +12,24 @@ constexpr float one_sixth = 1.0f/6.0f;
 
 namespace blank {
 
+GaloisLFSR::GaloisLFSR(std::uint64_t seed)
+: state(seed) {
+
+}
+
+bool GaloisLFSR::operator ()() {
+       bool result = state & 1;
+       state >>= 1;
+       if (result) {
+               state |= 0x8000000000000000;
+               state ^= mask;
+       } else {
+               state &= 0x7FFFFFFFFFFFFFFF;
+       }
+       return result;
+}
+
+
 SimplexNoise::SimplexNoise(unsigned int seed)
 : grad({
        {  1.0f,  1.0f,  0.0f },