device.h 748 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // random_impl.h
  3. // pokemon
  4. //
  5. // Created by Sam Jaffe on 12/9/17.
  6. //
  7. #pragma once
  8. #include <random/distribution.h>
  9. #include <random/forwards.h>
  10. #define IMPLEMENT_DEVICE(X) X(size_t) X(double) X(int32_t) X(uint32_t)
  11. #define TRIVIAL_RANDOM_DEVICE(T) \
  12. virtual T apply(Distribution<T> const & dist) { return dist(*this); }
  13. namespace engine::random {
  14. class Device {
  15. public:
  16. using result_type = uint32_t;
  17. constexpr static result_type min() { return 0; }
  18. constexpr static result_type max() { return ~0u; }
  19. virtual ~Device() = default;
  20. virtual result_type operator()() = 0;
  21. private:
  22. friend class Random;
  23. IMPLEMENT_DEVICE(TRIVIAL_RANDOM_DEVICE)
  24. };
  25. }
  26. #undef TRIVIAL_RANDOM_DEVICE