1 #ifndef BLANK_RAND_GALOISLFSR_HPP_
2 #define BLANK_RAND_GALOISLFSR_HPP_
13 // seed should be non-zero
14 explicit GaloisLFSR(std::uint64_t seed) noexcept
22 bool operator ()() noexcept {
23 bool result = state & 1;
26 state |= 0x8000000000000000;
29 state &= 0x7FFFFFFFFFFFFFFF;
35 T operator ()(T &out) noexcept {
36 constexpr int num_bits =
37 std::numeric_limits<T>::digits +
38 std::numeric_limits<T>::is_signed;
39 for (int i = 0; i < num_bits; ++i) {
42 return out = static_cast<T>(state);
51 template<class Container>
52 typename Container::reference From(Container &c) {
53 return c[Next<typename Container::size_type>() % c.size()];
55 template<class Container>
56 typename Container::const_reference From(const Container &c) {
57 return c[Next<typename Container::size_type>() % c.size()];
62 // bits 64, 63, 61, and 60 set to 1 (counting from 1 lo to hi)
63 static constexpr std::uint64_t mask = 0xD800000000000000;