Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. class Rand {
  2. private:
  3.     std::unique_ptr<std::mt19937> _mt;
  4.     std::random_device _rd;
  5.  
  6. public:
  7.     Rand() {
  8.         _mt = std::make_unique<std::mt19937>(_rd());
  9.     }
  10.  
  11.     std::mt19937 & get() { return *_mt.get(); }
  12.  
  13.     template<typename T>
  14.     T gen(T from, T to) {
  15.         std::uniform_int_distribution<T> d(from, to);
  16.         return d(get());
  17.     }
  18.  
  19.     template<typename T>
  20.     void enumgen(T & type) {
  21.         std::uniform_int_distribution<i32> d((i32)T::None + 1, (i32)T::Max - 1);
  22.         type = (T)d(get());
  23.     }
  24.  
  25.     bool prob(float num) {
  26.         std::bernoulli_distribution d(num);
  27.         return d(get());
  28.     }
  29. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement