tape.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // tape.hpp
  3. // shared_random_generator
  4. //
  5. // Created by Sam Jaffe on 3/19/23.
  6. // Copyright © 2023 Sam Jaffe. All rights reserved.
  7. //
  8. #pragma once
  9. #include <string>
  10. #include <tuple>
  11. #include <variant>
  12. #include <vector>
  13. #include <random/device.h>
  14. namespace engine::random {
  15. class Tape : public Device {
  16. public:
  17. // Allow for the serialization and de-serialization of this Tape
  18. using serial_type =
  19. std::vector<std::tuple<bool, std::string, double, double, double>>;
  20. private:
  21. enum class Type : char;
  22. template <typename T> struct EntryT;
  23. struct Entry;
  24. private:
  25. size_t index_{0}; // transient
  26. std::vector<Entry> entries_;
  27. public:
  28. Tape() = default;
  29. Tape(serial_type serial);
  30. explicit operator serial_type() const;
  31. unsigned int exclusive(unsigned int max) override;
  32. double exclusive(double min, double max) override;
  33. double inclusive(double min, double max) override;
  34. void exclusive(unsigned int max, unsigned int result);
  35. void exclusive(double min, double max, double result);
  36. void inclusive(double min, double max, double result);
  37. private:
  38. template <typename T> T fetch(Type type, T min, T max);
  39. };
  40. }