device.h 699 B

123456789101112131415161718192021222324252627282930313233
  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 APPLY_DEVICE(T) \
  11. virtual T apply(Distribution<T> const & dist) { return dist(*this); }
  12. namespace engine::random {
  13. class Device {
  14. public:
  15. using result_type = uint32_t;
  16. constexpr static result_type min() { return 0; }
  17. constexpr static result_type max() { return ~0u; }
  18. virtual ~Device() = default;
  19. virtual result_type operator()() = 0;
  20. private:
  21. friend class Random;
  22. APPLY_DEVICE(size_t)
  23. APPLY_DEVICE(double)
  24. APPLY_DEVICE(int32_t)
  25. APPLY_DEVICE(uint32_t)
  26. };
  27. }