random.h 968 B

123456789101112131415161718192021222324252627282930313233
  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. template <typename Rand>
  17. Rand operator()(Distribution<Rand> const & dist) const;
  18. /**
  19. * Create a scope in which all calls to the generator functions will record
  20. * their results into a tape. Expects that there is no tape currently set.
  21. * @param tape The tape to write to
  22. * @return A scope object that stops recording once it is descructed
  23. */
  24. scope_exit record(std::shared_ptr<Tape> tape);
  25. std::shared_ptr<Tape> tape() const { return tape_; }
  26. };
  27. }