diff --git a/soh/soh/Enhancements/randomizer/3drando/fill.cpp b/soh/soh/Enhancements/randomizer/3drando/fill.cpp index fad4178726..132b13f9fa 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 f8f6ffdd40..cc028c4c8d 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 4486895290..ff4d3beebd 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 882676e73e..30c81ef196 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 b0b3f796ee..0000000000 --- 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 1931460df2..6bc9570394 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 abd36b42bd..ae663c9d87 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 10892666a1..964eef8236 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 67d01e4b6e..c66617bbc7 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 ab73250cb6..ee5dd5b061 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 70697d8b06..3a4e7d2e0e 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/3drando/random.hpp b/soh/soh/Enhancements/randomizer/rng.h similarity index 63% rename from soh/soh/Enhancements/randomizer/3drando/random.hpp rename to soh/soh/Enhancements/randomizer/rng.h index 5c8eefd3b5..b2f86ab68e 100644 --- a/soh/soh/Enhancements/randomizer/3drando/random.hpp +++ b/soh/soh/Enhancements/randomizer/rng.h @@ -4,15 +4,24 @@ #include #include #include -#include #include #include -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 T RandomElement(std::vector& vector, bool erase) { @@ -30,14 +39,9 @@ template const T RandomElementFromSet(const std::set& set) { } // 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()))]); - } + ShipUtils::Shuffle(vector, &rando_state); } 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()))]); - } + ShipUtils::Shuffle(arr, &rando_state); } diff --git a/soh/soh/Enhancements/randomizer/settings.cpp b/soh/soh/Enhancements/randomizer/settings.cpp index eba220edad..17a6930ed1 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