Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <typename U = uint64_t> class RandomizerWithShiftT {
- public:
- template <typename Rng> bool operator()(Rng &rng) {
- if (UNLIKELY(1 == m_rand)) {
- m_rand = std::uniform_int_distribution<U>{}(rng) | s_mask_left1;
- }
- bool const ret = m_rand & 1;
- m_rand >>= 1;
- return ret;
- }
- private:
- static constexpr const U s_mask_left1 = U(1) << (sizeof(U) * 8 - 1);
- U m_rand = 1;
- };
- template <typename U = uint64_t> class RandomizerInt extends RandomizerWithShiftT(int size) {
- public :
- template <typename Rng> bool operator()(Rng &rng){
- int res = 0;
- for(int i = 0 ; i<size;i++)
- res += parent::operator(&rng) << i ;
- return res;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement