Files
st/include/System/Random.hpp
T
Yanis 5e934a8c9b Decompile overlay 24 (Part 3) (#68)
* name func_01ffd3d8 and func_01ffd400

* name func_01ffd3b0

* match func_ov024_020cf9d4 + improve the Random struct

* UnkStruct_027e0cf8_00_0C_024 45%

* match PassengerManager::GetRandomIndex

* UnkStruct_027e0cf8_00_0C_024 OK

* UnkStruct_027e0cf8_00_0C_024: do other sections

* UnkStruct_027e0cf8_08_024 55%

* cleanup: remplace delete into null by the delete macro

* UnkStruct_027e0cf8_08_024 OK

* fix build issues

* UnkStruct_ov024_020d86a0_024 OK

* PlayerActor_A0_38_024 .text OK, CreditsEndingType OK

* tools: create courselist.py to convert .CLB data to yaml

* UnkDataStruct4_14 OK

* UnkDataStruct4 17%

* UnkDataStruct4 OK

* MiscAdvManager OK

* PassengerManager OK

* fix build issues

* ZeldaTrainBinary OK

* mark PassengerManager as complete and adjust delinks

* UnkStruct_027e0cf8_08_00_024 OK

* document more of UnkStruct_027e0ce0

* savefile hotfixes

* UnkStruct_027e0ce0_34_024 OK

* code_020d46b4_024 OK

* UnkStruct_027e0d00 & UnkStruct_027e0d00_20 OK

* code_020d51dc_024 OK

* fix weird formatting

* UnkTrainSystem1 OK

* fix jp broken match

* UnkTrainSystem2 OK

* UnkStruct_027e0d08_024 31%

* fix build issues

* UnkStruct_027e0d08 OK!!!

* remove useless parenthesis

* ActorUnk_ov000_020a8bb0_EC OK

* move ActorUnk_ov000_020a8bb0_EC to MainGame/Actor/

* ActorUnkOBPC OK

* add sjiswrap support

* solve remaining gaps and fix build issues

* reorganise files + counter docs

* tools: remove format command execution from defaults
2026-06-09 23:01:32 +02:00

98 lines
2.0 KiB
C++

#pragma once
#include "global.h"
#include "math.hpp"
#include "types.h"
struct Random {
/* 00 */ u16 mRandomValue[4];
/* 08 */ u64 mFactor;
/* 10 */ u64 mAddend;
/* 18 */
/**
* @brief Gets the seed's value
*/
u64 GetRandomValue() {
return *(u64 *) this->mRandomValue;
}
/**
* @brief Sets the seed's value from a u64
*/
void SetRandomValue(u64 value) {
*(u64 *) this->mRandomValue = value;
}
/**
* @brief Sets the seed's value from a u16 array
*/
void SetRandomValue(u16 *value) {
this->SetRandomValue(*(u64 *) value);
}
/**
* @brief Setup the randomizer with a set seed as a u64
*/
void Setup(u64 initial) {
this->SetRandomValue(initial);
this->SetFactorAddend();
}
/**
* @brief Setup the randomizer with a set seed as a u16 array
*/
void Setup(u16 *initial) {
this->SetRandomValue(initial);
this->SetFactorAddend();
}
/**
* @brief Setup the randomizer without any specific seed
*/
void Setup() {
this->SetRandomValue((u64) 0);
this->SetFactorAddend();
}
/**
* @brief Sets the factor and addend values
*/
void SetFactorAddend() {
this->mFactor = 0x5D588B656C078965;
this->mAddend = 0x00269EC3;
}
/**
* @brief Updates the seed's value
*/
void UpdateRandomValue() {
*(u64 *) this->mRandomValue = this->mAddend + (this->mFactor * this->GetRandomValue());
}
/**
* @brief Generates a random number as u32
*/
u32 Next32(u32 factor) {
this->UpdateRandomValue();
u64 randomValue = this->GetRandomValue();
if (factor == 0) {
return randomValue >> 32;
}
return ((randomValue >> 32) * factor) >> 32;
}
/**
* @brief Generates a random number as u32 then convert it to a u16
*/
u16 Next16(u32 factor) {
return this->Next32(factor) >> 16;
}
void Init();
};
extern Random gRandom;