| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //
- // tape.hpp
- // shared_random_generator
- //
- // Created by Sam Jaffe on 3/19/23.
- // Copyright © 2023 Sam Jaffe. All rights reserved.
- //
- #pragma once
- #include <string>
- #include <tuple>
- #include <variant>
- #include <vector>
- #include <random/device.h>
- namespace engine::random {
- class Tape : public Device {
- public:
- // Allow for the serialization and de-serialization of this Tape
- using serial_type =
- std::vector<std::tuple<bool, std::string, double, double, double>>;
- private:
- enum class Type : char;
- template <typename T> struct EntryT {
- EntryT(T min, T max) : min(min), max(max), result() {}
- EntryT(T min, T max, T result) : min(min), max(max), result(result) {}
- T min;
- T max;
- T result;
- };
-
- struct Entry {
- template <typename T>
- Entry(Type type, EntryT<T> params) : type(type), params(params) {}
- Type type;
- std::variant<EntryT<double>, EntryT<unsigned int>> params;
- };
- private:
- size_t index_{0}; // transient
- std::vector<Entry> entries_;
- public:
- Tape() = default;
- Tape(serial_type serial);
- explicit operator serial_type() const;
- unsigned int exclusive(unsigned int max) override;
- double exclusive(double min, double max) override;
- double inclusive(double min, double max) override;
- void exclusive(unsigned int max, unsigned int result);
- void exclusive(double min, double max, double result);
- void inclusive(double min, double max, double result);
- private:
- template <typename T> T fetch(Type type, T min, T max);
- };
- }
|