Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. template <typename U = uint64_t> class RandomizerWithShiftT {
  2.     public:
  3.         template <typename Rng> bool operator()(Rng &rng) {
  4.             if (UNLIKELY(1 == m_rand)) {
  5.                 m_rand = std::uniform_int_distribution<U>{}(rng) | s_mask_left1;
  6.             }  
  7.             bool const ret = m_rand & 1;
  8.             m_rand >>= 1;
  9.             return ret;
  10.         }  
  11.  
  12.     private:
  13.         static constexpr const U s_mask_left1 = U(1) << (sizeof(U) * 8 - 1);
  14.         U m_rand = 1;
  15. };
  16.  
  17. template <typename U = uint64_t> class RandomizerInt extends RandomizerWithShiftT(int size) {
  18.     public :
  19.         template <typename Rng> bool operator()(Rng &rng){
  20.             int res = 0;
  21.             for(int i = 0 ; i<size;i++)
  22.                 res += parent::operator(&rng) << i ;
  23.  
  24.             return res;
  25.         }  
  26. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement