diff options
| author | Philip Dubé <159546+serprex@users.noreply.github.com> | 2026-07-20 13:13:02 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-20 13:13:02 +0000 |
| commit | a236e9ec84fb8b49443e6a167aeda6f98cb8c7fe (patch) | |
| tree | 27d0ce15144f04a3e4b843d1af32dd2547c523e5 /soh | |
| parent | 1ea7206073183e7f7424e02eceb44d4d9bf35300 (diff) | |
randomizer/rng.h (#6947)
Diffstat (limited to 'soh')
| -rw-r--r-- | soh/soh/Enhancements/randomizer/3drando/fill.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/3drando/hints.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/3drando/item_pool.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/3drando/playthrough.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/3drando/random.cpp | 20 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/3drando/shops.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/SeedContext.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/Traps.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/entrance.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/hint.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/item_location.cpp | 2 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/rng.h (renamed from soh/soh/Enhancements/randomizer/3drando/random.hpp) | 28 | ||||
| -rw-r--r-- | soh/soh/Enhancements/randomizer/settings.cpp | 2 |
13 files changed, 27 insertions, 43 deletions
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 <algorithm> #include <spdlog/spdlog.h> 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 <spdlog/spdlog.h> #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/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 <vector> 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 <vector> 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 <spdlog/spdlog.h> #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 <spdlog/spdlog.h> diff --git a/soh/soh/Enhancements/randomizer/3drando/random.hpp b/soh/soh/Enhancements/randomizer/rng.h index 5c8eefd3b..b2f86ab68 100644 --- a/soh/soh/Enhancements/randomizer/3drando/random.hpp +++ b/soh/soh/Enhancements/randomizer/rng.h @@ -4,15 +4,24 @@ #include <array> #include <cstddef> #include <stdint.h> -#include <utility> #include <vector> #include <set> -extern uint64_t rando_state; +inline uint64_t rando_state = 0; -void Random_Init(uint64_t seed); -uint32_t Random(uint32_t min, uint32_t max); -double RandomDouble(); +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 <typename T> T RandomElement(std::vector<T>& vector, bool erase) { @@ -30,14 +39,9 @@ template <typename T> const T RandomElementFromSet(const std::set<T>& set) { } // Shuffle items within a vector or array -// RANDOTODO There's probably a more efficient way to do what this does. template <typename T> void Shuffle(std::vector<T>& vector) { - for (size_t i = 0; i + 1 < vector.size(); i++) { - std::swap(vector[i], vector[Random(static_cast<uint32_t>(i), static_cast<uint32_t>(vector.size()))]); - } + ShipUtils::Shuffle(vector, &rando_state); } template <typename T, size_t size> void Shuffle(std::array<T, size>& arr) { - for (size_t i = 0; i + 1 < arr.size(); i++) { - std::swap(arr[i], arr[Random(static_cast<uint32_t>(i), static_cast<uint32_t>(arr.size()))]); - } + 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 <spdlog/spdlog.h> |
