]> git.localhorst.tv Git - blank.git/blobdiff - src/rand/GaloisLFSR.hpp
test random ints of various widths
[blank.git] / src / rand / GaloisLFSR.hpp
index 2ee476b6e321cc5d0298993b75e134b0727aeaad..81652d85f54a64cd628c22a95d3493b6de6476cd 100644 (file)
@@ -42,12 +42,25 @@ 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) {
                return c[Next<typename Container::size_type>() % c.size()];