X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Frand%2FGaloisLFSR.hpp;h=f8a61e23f3f7c721689d7e0ff4a2404aa671f412;hb=fab49d91255ef7d265817213c3da7e5f81df97a0;hp=f5de7ad0bb650f15d9d6870d82e3bd6f3ee97b70;hpb=150d065f431d665326fd8028748c48a74ad956bb;p=blank.git diff --git a/src/rand/GaloisLFSR.hpp b/src/rand/GaloisLFSR.hpp index f5de7ad..f8a61e2 100644 --- a/src/rand/GaloisLFSR.hpp +++ b/src/rand/GaloisLFSR.hpp @@ -1,6 +1,7 @@ #ifndef BLANK_RAND_GALOISLFSR_HPP_ #define BLANK_RAND_GALOISLFSR_HPP_ +#include #include #include @@ -42,6 +43,11 @@ public: return out = static_cast(state); } + /// special case for randrom(boolean), since static_cast(0b10) == true + bool operator ()(bool &out) noexcept { + return out = operator ()(); + } + template T Next() noexcept { T next; @@ -58,10 +64,12 @@ public: template typename Container::reference From(Container &c) { + assert(c.size() > 0); return c[Next() % c.size()]; } template typename Container::const_reference From(const Container &c) { + assert(c.size() > 0); return c[Next() % c.size()]; }