| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //
- // 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<std::string, uint64_t, uint64_t, uint64_t>>;
- private:
- 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) {}
- EntryT(uint64_t min, uint64_t max, uint64_t result);
- T min;
- T max;
- T result;
- };
- using Entry = std::variant<EntryT<double>, EntryT<uint32_t>, EntryT<int32_t>>;
- private:
- size_t index_{0}; // transient
- std::vector<Entry> entries_;
- public:
- Tape() = default;
- Tape(serial_type serial);
- explicit operator serial_type() const;
- int32_t inclusive(int32_t min, int32_t max) override {
- return fetch(min, max);
- }
- uint32_t inclusive(uint32_t min, uint32_t max) override {
- return fetch(min, max);
- }
- double exclusive(double min, double max) override { return fetch(min, max); }
- void inclusive(int32_t min, int32_t max, int32_t result);
- void inclusive(uint32_t min, uint32_t max, uint32_t result);
- void exclusive(double min, double max, double result);
- private:
- template <typename T> T fetch(T min, T max);
- };
- }
|