summaryrefslogtreecommitdiff
path: root/src/util/include/random.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/include/random.hpp')
-rw-r--r--src/util/include/random.hpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/util/include/random.hpp b/src/util/include/random.hpp
new file mode 100644
index 00000000..cd8ab1c6
--- /dev/null
+++ b/src/util/include/random.hpp
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#pragma once
+
+#include <cstdint>
+
+#include "komihash.h"
+
+namespace util {
+
+class IRandom {
+ public:
+ virtual ~IRandom() {}
+
+ virtual auto Next() -> std::uint64_t = 0;
+ virtual auto RangeInclusive(std::uint64_t lower, std::uint64_t upper)
+ -> std::uint64_t = 0;
+};
+
+extern IRandom* sRandom;
+
+class Random : public IRandom {
+ public:
+ Random();
+
+ auto Next() -> std::uint64_t override;
+ auto RangeInclusive(std::uint64_t lower, std::uint64_t upper)
+ -> std::uint64_t override;
+
+ private:
+ std::uint64_t seed1_;
+ std::uint64_t seed2_;
+};
+
+} // namespace util