randomizer/rng.h (#6947)

This commit is contained in:
Philip Dubé
2026-07-20 13:13:02 +00:00
committed by GitHub
parent 1ea7206073
commit a236e9ec84
13 changed files with 27 additions and 43 deletions
@@ -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"
@@ -1,6 +1,6 @@
#include "hints.hpp"
#include "random.hpp"
#include "../rng.h"
#include "fill.hpp"
#include "../trial.h"
#include "../entrance.h"
@@ -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>
@@ -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"
@@ -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);
}
@@ -1,6 +1,6 @@
#include "item_pool.hpp"
#include "../location_access.h"
#include "random.hpp"
#include "../rng.h"
#include "shops.hpp"
#include "../location.h"
@@ -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>
+1 -1
View File
@@ -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>
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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() {
@@ -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>
@@ -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);
}
+1 -1
View File
@@ -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>