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 float SNorm() noexcept {
52 return float(Next<std::uint32_t>()) * (1.0f / 2147483647.5f) - 1.0f;
55 float UNorm() noexcept {
56 return float(Next<std::uint32_t>()) * (1.0f / 4294967295.0f);
59 template<class Container>
60 typename Container::reference From(Container &c) {
61 return c[Next<typename Container::size_type>() % c.size()];
63 template<class Container>
64 typename Container::const_reference From(const Container &c) {
65 return c[Next<typename Container::size_type>() % c.size()];
70 // bits 64, 63, 61, and 60 set to 1 (counting from 1 lo to hi)
71 static constexpr std::uint64_t mask = 0xD800000000000000;