diff --git a/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp b/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp index ac99859b5..7ad07eb70 100644 --- a/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp +++ b/soh/soh/Enhancements/game-interactor/GameInteractor_RawAction.cpp @@ -617,7 +617,7 @@ GameInteractionEffectQueryResult GameInteractor::RawAction::SpawnEnemyWithOffset } // Generate point in random angle with a radius. - float angle = Random(0, 2 * M_PI); + float angle = Random_Float(0, 2 * M_PI); float radius = 150; float posXOffset = radius * cos(angle); float posZOffset = radius * sin(angle); diff --git a/soh/soh/Enhancements/randomizer/3drando/random.cpp b/soh/soh/Enhancements/randomizer/3drando/random.cpp index f2599da94..c37aa118b 100644 --- a/soh/soh/Enhancements/randomizer/3drando/random.cpp +++ b/soh/soh/Enhancements/randomizer/3drando/random.cpp @@ -14,8 +14,7 @@ void Random_Init(uint32_t seed) { generator = boost::random::mt19937{ seed }; } -// Returns a random integer in range [min, max-1] -uint32_t Random(int min, int max) { +void Random_InitSeed() { if (!init) { // No seed given, get a random number from device to seed #if !defined(__SWITCH__) && !defined(__WIIU__) @@ -25,10 +24,22 @@ uint32_t Random(int min, int max) { #endif Random_Init(seed); } +} + +// Returns a random unsigned integer in range [min, max-1] +uint32_t Random(uint32_t min, uint32_t max) { + Random_InitSeed(); boost::random::uniform_int_distribution distribution(min, max - 1); return distribution(generator); } +// Returns a random float in range [min, max-1] +float Random_Float(float min, float max) { + Random_InitSeed(); + boost::random::uniform_real_distribution distribution(min, max - 1); + return distribution(generator); +} + // Returns a random floating point number in [0.0, 1.0] double RandomDouble() { boost::random::uniform_real_distribution distribution(0.0, 1.0); diff --git a/soh/soh/Enhancements/randomizer/3drando/random.hpp b/soh/soh/Enhancements/randomizer/3drando/random.hpp index cc519d5f9..1ad054735 100644 --- a/soh/soh/Enhancements/randomizer/3drando/random.hpp +++ b/soh/soh/Enhancements/randomizer/3drando/random.hpp @@ -8,7 +8,8 @@ #include void Random_Init(uint32_t seed); -uint32_t Random(int min, int max); +uint32_t Random(uint32_t min, uint32_t max); +float Random_Float(float min, float max); double RandomDouble(); // Get a random element from a vector or array @@ -21,17 +22,17 @@ template T RandomElement(std::vector& vector, bool erase) { return selected; } template auto& RandomElement(Container& container) { - return container[Random(0, std::size(container))]; + return container[Random(0, (uint32_t)std::size(container))]; } template const auto& RandomElement(const Container& container) { - return container[Random(0, std::size(container))]; + return container[Random(0, (uint32_t)std::size(container))]; } template const T RandomElementFromSet(const std::set& set) { if (set.size() == 1) { return *set.begin(); } - uint32_t rand = Random(0, set.size()); + uint32_t rand = Random(0, (uint32_t)set.size()); auto it = set.begin(); for (uint32_t i = 0; i < rand; i++) { it++; @@ -43,12 +44,12 @@ 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 (std::size_t i = 0; i + 1 < vector.size(); i++) { - std::swap(vector[i], vector[Random(i, vector.size())]); + for (size_t i = 0; i + 1 < vector.size(); i++) { + std::swap(vector[i], vector[Random((uint32_t)i, (uint32_t)vector.size())]); } } -template void Shuffle(std::array& arr) { - for (std::size_t i = 0; i + 1 < arr.size(); i++) { - std::swap(arr[i], arr[Random(i, arr.size())]); +template void Shuffle(std::array& arr) { + for (size_t i = 0; i + 1 < arr.size(); i++) { + std::swap(arr[i], arr[Random((uint32_t)i, (uint32_t)arr.size())]); } }