| 1234567891011121314151617181920212223242526272829303132333435363738 |
- #pragma once
- #include <cassert>
- #include <memory>
- #include <random/forwards.h>
- namespace engine::random {
- class Random {
- private:
- std::shared_ptr<Device> impl_;
- std::shared_ptr<Tape> tape_{nullptr};
- public:
- Random();
- template <typename P> Random(P const & p) : impl_(std::make_shared<P>(p)) {}
- template <typename P> Random(std::shared_ptr<P> const & p) : impl_(p) {}
-
- unsigned int exclusive(unsigned int max) const;
- double exclusive(double min, double max) const;
- double inclusive(double min, double max) const;
-
- std::shared_ptr<Device> device() const { return impl_; }
-
- /**
- * Create a scope in which all calls to the generator functions will record
- * their results into a tape. Expects that there is no tape currently set.
- * @param tape The tape to write to
- * @return A scope object that stops recording once it is descructed
- */
- auto record(std::shared_ptr<Tape> tape) {
- assert(tape && !tape_);
- tape_ = tape;
- auto cleanup = [this](void *) { tape_.reset(); };
- return std::unique_ptr<void, decltype(cleanup)>(nullptr, cleanup);
- }
- };
- }
|