random.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <cassert>
  3. #include <memory>
  4. #include <random/forwards.h>
  5. namespace engine::random {
  6. class Random {
  7. private:
  8. std::shared_ptr<Device> impl_;
  9. std::shared_ptr<Tape> tape_{nullptr};
  10. public:
  11. Random();
  12. Random(Random const & other, Tape & with_tape);
  13. Random(Random const & other, std::shared_ptr<Tape> with_tape);
  14. template <typename P> Random(P const & p) : impl_(std::make_shared<P>(p)) {}
  15. template <typename P> Random(std::shared_ptr<P> const & p) : impl_(p) {}
  16. int32_t exclusive(int32_t min, int32_t max) const;
  17. int32_t inclusive(int32_t min, int32_t max) const;
  18. uint32_t exclusive(uint32_t min, uint32_t max) const;
  19. uint32_t inclusive(uint32_t min, uint32_t max) const;
  20. double exclusive(double min, double max) const;
  21. double inclusive(double min, double max) const;
  22. std::shared_ptr<Device> device() const { return impl_; }
  23. /**
  24. * Create a scope in which all calls to the generator functions will record
  25. * their results into a tape. Expects that there is no tape currently set.
  26. * @param tape The tape to write to
  27. * @return A scope object that stops recording once it is descructed
  28. */
  29. scope_exit record(std::shared_ptr<Tape> tape);
  30. };
  31. }