random.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  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. unsigned int exclusive(unsigned int max) const;
  17. double exclusive(double min, double max) const;
  18. double inclusive(double min, double max) const;
  19. std::shared_ptr<Device> device() const { return impl_; }
  20. /**
  21. * Create a scope in which all calls to the generator functions will record
  22. * their results into a tape. Expects that there is no tape currently set.
  23. * @param tape The tape to write to
  24. * @return A scope object that stops recording once it is descructed
  25. */
  26. scope_exit record(std::shared_ptr<Tape> tape);
  27. };
  28. }