]> git.localhorst.tv Git - blank.git/blobdiff - src/rand/GaloisLFSR.hpp
also join processes terminated by signal
[blank.git] / src / rand / GaloisLFSR.hpp
index f5de7ad0bb650f15d9d6870d82e3bd6f3ee97b70..f8a61e23f3f7c721689d7e0ff4a2404aa671f412 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef BLANK_RAND_GALOISLFSR_HPP_
 #define BLANK_RAND_GALOISLFSR_HPP_
 
+#include <cassert>
 #include <cstdint>
 #include <limits>
 
@@ -42,6 +43,11 @@ 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;
@@ -58,10 +64,12 @@ public:
 
        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()];
        }