]> git.localhorst.tv Git - blank.git/blobdiff - src/rand/GaloisLFSR.hpp
fix assert inclusion in rand
[blank.git] / src / rand / GaloisLFSR.hpp
index 2ee476b6e321cc5d0298993b75e134b0727aeaad..f8a61e23f3f7c721689d7e0ff4a2404aa671f412 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef BLANK_RAND_GALOISLFSR_HPP_
 #define BLANK_RAND_GALOISLFSR_HPP_
 
+#include <cassert>
 #include <cstdint>
 #include <limits>
 
@@ -42,18 +43,33 @@ public:
                return out = static_cast<T>(state);
        }
 
+       /// special case for randrom(boolean), since static_cast<bool>(0b10) == true
+       bool operator ()(bool &out) noexcept {
+               return out = operator ()();
+       }
+
        template<class T>
        T Next() noexcept {
                T next;
                return (*this)(next);
        }
 
+       float SNorm() noexcept {
+               return float(Next<std::uint32_t>()) * (1.0f / 2147483647.5f) - 1.0f;
+       }
+
+       float UNorm() noexcept {
+               return float(Next<std::uint32_t>()) * (1.0f / 4294967295.0f);
+       }
+
        template<class Container>
        typename Container::reference From(Container &c) {
+               assert(c.size() > 0);
                return c[Next<typename Container::size_type>() % c.size()];
        }
        template<class Container>
        typename Container::const_reference From(const Container &c) {
+               assert(c.size() > 0);
                return c[Next<typename Container::size_type>() % c.size()];
        }