From a236e9ec84fb8b49443e6a167aeda6f98cb8c7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20Dub=C3=A9?= <159546+serprex@users.noreply.github.com> Date: Mon, 20 Jul 2026 13:13:02 +0000 Subject: randomizer/rng.h (#6947) --- soh/soh/Enhancements/randomizer/3drando/fill.cpp | 2 +- soh/soh/Enhancements/randomizer/3drando/hints.cpp | 2 +- .../Enhancements/randomizer/3drando/item_pool.cpp | 2 +- .../randomizer/3drando/playthrough.cpp | 2 +- soh/soh/Enhancements/randomizer/3drando/random.cpp | 20 --------- soh/soh/Enhancements/randomizer/3drando/random.hpp | 43 -------------------- soh/soh/Enhancements/randomizer/3drando/shops.cpp | 2 +- soh/soh/Enhancements/randomizer/SeedContext.cpp | 2 +- soh/soh/Enhancements/randomizer/Traps.cpp | 2 +- soh/soh/Enhancements/randomizer/entrance.cpp | 2 +- soh/soh/Enhancements/randomizer/hint.cpp | 2 +- soh/soh/Enhancements/randomizer/item_location.cpp | 2 +- soh/soh/Enhancements/randomizer/rng.h | 47 ++++++++++++++++++++++ soh/soh/Enhancements/randomizer/settings.cpp | 2 +- 14 files changed, 58 insertions(+), 74 deletions(-) delete mode 100644 soh/soh/Enhancements/randomizer/3drando/random.cpp delete mode 100644 soh/soh/Enhancements/randomizer/3drando/random.hpp create mode 100644 soh/soh/Enhancements/randomizer/rng.h diff --git a/soh/soh/Enhancements/randomizer/3drando/fill.cpp b/soh/soh/Enhancements/randomizer/3drando/fill.cpp index fad417872..132b13f9f 100644 --- a/soh/soh/Enhancements/randomizer/3drando/fill.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/fill.cpp @@ -5,7 +5,7 @@ #include "item_pool.hpp" #include "starting_inventory.hpp" #include "hints.hpp" -#include "random.hpp" +#include "../rng.h" #include "shops.hpp" #include "pool_functions.hpp" #include "soh/Enhancements/randomizer/static_data.h" diff --git a/soh/soh/Enhancements/randomizer/3drando/hints.cpp b/soh/soh/Enhancements/randomizer/3drando/hints.cpp index f8f6ffdd4..cc028c4c8 100644 --- a/soh/soh/Enhancements/randomizer/3drando/hints.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/hints.cpp @@ -1,6 +1,6 @@ #include "hints.hpp" -#include "random.hpp" +#include "../rng.h" #include "fill.hpp" #include "../trial.h" #include "../entrance.h" diff --git a/soh/soh/Enhancements/randomizer/3drando/item_pool.cpp b/soh/soh/Enhancements/randomizer/3drando/item_pool.cpp index 448689529..ff4d3beeb 100644 --- a/soh/soh/Enhancements/randomizer/3drando/item_pool.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/item_pool.cpp @@ -4,7 +4,7 @@ #include "fill.hpp" #include "../static_data.h" #include "../SeedContext.h" -#include "random.hpp" +#include "../rng.h" #include "soh/Enhancements/randomizer/Traps.h" #include #include diff --git a/soh/soh/Enhancements/randomizer/3drando/playthrough.cpp b/soh/soh/Enhancements/randomizer/3drando/playthrough.cpp index 882676e73..30c81ef19 100644 --- a/soh/soh/Enhancements/randomizer/3drando/playthrough.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/playthrough.cpp @@ -3,7 +3,7 @@ #include #include "fill.hpp" #include "../location_access.h" -#include "random.hpp" +#include "../rng.h" #include "spoiler_log.hpp" #include "soh/Enhancements/randomizer/settings.h" #include "variables.h" diff --git a/soh/soh/Enhancements/randomizer/3drando/random.cpp b/soh/soh/Enhancements/randomizer/3drando/random.cpp deleted file mode 100644 index b0b3f796e..000000000 --- a/soh/soh/Enhancements/randomizer/3drando/random.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "random.hpp" - -uint64_t rando_state = 0; -const uint64_t multiplier = 6364136223846793005ULL; -const uint64_t increment = 11634580027462260723ULL; - -// Initialize with seed specified -void Random_Init(uint64_t seed) { - ShipUtils::RandInit(seed, &rando_state); -} - -// Returns a random integer in range [min, max-1] -uint32_t Random(uint32_t min, uint32_t max) { - return ShipUtils::Random(min, max, &rando_state); -} - -// Returns a random floating point number in [0.0, 1.0) -double RandomDouble() { - return ShipUtils::RandomDouble(&rando_state); -} diff --git a/soh/soh/Enhancements/randomizer/3drando/random.hpp b/soh/soh/Enhancements/randomizer/3drando/random.hpp deleted file mode 100644 index 5c8eefd3b..000000000 --- a/soh/soh/Enhancements/randomizer/3drando/random.hpp +++ /dev/null @@ -1,43 +0,0 @@ -#pragma once - -#include "soh/ShipUtils.h" -#include -#include -#include -#include -#include -#include - -extern uint64_t rando_state; - -void Random_Init(uint64_t seed); -uint32_t Random(uint32_t min, uint32_t max); -double RandomDouble(); - -// Get a random element from a vector or array -template T RandomElement(std::vector& vector, bool erase) { - return ShipUtils::RandomElement(vector, erase, &rando_state); -} -template auto& RandomElement(Container& container) { - return ShipUtils::RandomElement(container, &rando_state); -} -template const auto& RandomElement(const Container& container) { - return ShipUtils::RandomElement(container, &rando_state); -} - -template const T RandomElementFromSet(const std::set& set) { - return ShipUtils::RandomElementFromSet(set, &rando_state); -} - -// Shuffle items within a vector or array -// RANDOTODO There's probably a more efficient way to do what this does. -template void Shuffle(std::vector& vector) { - for (size_t i = 0; i + 1 < vector.size(); i++) { - std::swap(vector[i], vector[Random(static_cast(i), static_cast(vector.size()))]); - } -} -template void Shuffle(std::array& arr) { - for (size_t i = 0; i + 1 < arr.size(); i++) { - std::swap(arr[i], arr[Random(static_cast(i), static_cast(arr.size()))]); - } -} diff --git a/soh/soh/Enhancements/randomizer/3drando/shops.cpp b/soh/soh/Enhancements/randomizer/3drando/shops.cpp index 1931460df..6bc957039 100644 --- a/soh/soh/Enhancements/randomizer/3drando/shops.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/shops.cpp @@ -1,6 +1,6 @@ #include "item_pool.hpp" #include "../location_access.h" -#include "random.hpp" +#include "../rng.h" #include "shops.hpp" #include "../location.h" diff --git a/soh/soh/Enhancements/randomizer/SeedContext.cpp b/soh/soh/Enhancements/randomizer/SeedContext.cpp index abd36b42b..ae663c9d8 100644 --- a/soh/soh/Enhancements/randomizer/SeedContext.cpp +++ b/soh/soh/Enhancements/randomizer/SeedContext.cpp @@ -13,7 +13,7 @@ #include "soh/util.h" #include "../kaleido.h" #include "soh/Enhancements/randomizer/Traps.h" -#include "soh/Enhancements/randomizer/3drando/random.hpp" +#include "soh/Enhancements/randomizer/rng.h" #include "soh/Enhancements/randomizer/randomizer.h" #include diff --git a/soh/soh/Enhancements/randomizer/Traps.cpp b/soh/soh/Enhancements/randomizer/Traps.cpp index 10892666a..964eef823 100644 --- a/soh/soh/Enhancements/randomizer/Traps.cpp +++ b/soh/soh/Enhancements/randomizer/Traps.cpp @@ -3,7 +3,7 @@ #include "soh/Enhancements/randomizer/static_data.h" #include "soh/ShipUtils.h" -#include "soh/Enhancements/randomizer/3drando/random.hpp" +#include "soh/Enhancements/randomizer/rng.h" #include diff --git a/soh/soh/Enhancements/randomizer/entrance.cpp b/soh/soh/Enhancements/randomizer/entrance.cpp index 67d01e4b6..c66617bbc 100644 --- a/soh/soh/Enhancements/randomizer/entrance.cpp +++ b/soh/soh/Enhancements/randomizer/entrance.cpp @@ -3,7 +3,7 @@ #include "3drando/fill.hpp" #include "3drando/pool_functions.hpp" #include "3drando/item_pool.hpp" -#include "3drando/random.hpp" +#include "rng.h" #include "../debugger/performanceTimer.h" #include "soh/Enhancements/gameconsole.h" #include "z64camera.h" diff --git a/soh/soh/Enhancements/randomizer/hint.cpp b/soh/soh/Enhancements/randomizer/hint.cpp index ab73250cb..ee5dd5b06 100644 --- a/soh/soh/Enhancements/randomizer/hint.cpp +++ b/soh/soh/Enhancements/randomizer/hint.cpp @@ -3,7 +3,7 @@ #include "SeedContext.h" #include #include "static_data.h" -#include "3drando/random.hpp" +#include "rng.h" namespace Rando { Hint::Hint() { diff --git a/soh/soh/Enhancements/randomizer/item_location.cpp b/soh/soh/Enhancements/randomizer/item_location.cpp index 70697d8b0..3a4e7d2e0 100644 --- a/soh/soh/Enhancements/randomizer/item_location.cpp +++ b/soh/soh/Enhancements/randomizer/item_location.cpp @@ -1,7 +1,7 @@ #include "item_location.h" #include "SeedContext.h" #include "logic.h" -#include "3drando/random.hpp" +#include "rng.h" #include diff --git a/soh/soh/Enhancements/randomizer/rng.h b/soh/soh/Enhancements/randomizer/rng.h new file mode 100644 index 000000000..b2f86ab68 --- /dev/null +++ b/soh/soh/Enhancements/randomizer/rng.h @@ -0,0 +1,47 @@ +#pragma once + +#include "soh/ShipUtils.h" +#include +#include +#include +#include +#include + +inline uint64_t rando_state = 0; + +static inline void Random_Init(uint64_t seed) { + ShipUtils::RandInit(seed, &rando_state); +} + +// Returns a random integer in range [min, max-1] +static inline uint32_t Random(uint32_t min, uint32_t max) { + return ShipUtils::Random(min, max, &rando_state); +} + +// Returns a random floating point number in [0.0, 1.0) +static inline double RandomDouble() { + return ShipUtils::RandomDouble(&rando_state); +} + +// Get a random element from a vector or array +template T RandomElement(std::vector& vector, bool erase) { + return ShipUtils::RandomElement(vector, erase, &rando_state); +} +template auto& RandomElement(Container& container) { + return ShipUtils::RandomElement(container, &rando_state); +} +template const auto& RandomElement(const Container& container) { + return ShipUtils::RandomElement(container, &rando_state); +} + +template const T RandomElementFromSet(const std::set& set) { + return ShipUtils::RandomElementFromSet(set, &rando_state); +} + +// Shuffle items within a vector or array +template void Shuffle(std::vector& vector) { + ShipUtils::Shuffle(vector, &rando_state); +} +template void Shuffle(std::array& arr) { + ShipUtils::Shuffle(arr, &rando_state); +} diff --git a/soh/soh/Enhancements/randomizer/settings.cpp b/soh/soh/Enhancements/randomizer/settings.cpp index eba220eda..17a6930ed 100644 --- a/soh/soh/Enhancements/randomizer/settings.cpp +++ b/soh/soh/Enhancements/randomizer/settings.cpp @@ -2,7 +2,7 @@ #include "trial.h" #include "dungeon.h" #include "soh/Enhancements/randomizer/randomizerTypes.h" -#include "soh/Enhancements/randomizer/3drando/random.hpp" +#include "soh/Enhancements/randomizer/rng.h" #include "soh/OTRGlobals.h" #include -- cgit v1.2.3