mirror of
https://github.com/zeldaret/st
synced 2026-05-23 15:01:41 -04:00
66ad81ba15
* move nitro headers to libs/nitro/include and setup sbc.c Co-authored-by: enzofc708 <47937189+enzofc708@users.noreply.github.com> * sbc.c 95% * move sbc in the right folder (and fix a warning) * revert formating changes --------- Co-authored-by: enzofc708 <47937189+enzofc708@users.noreply.github.com>
59 lines
1.2 KiB
C++
59 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include "global.h"
|
|
#include "types.h"
|
|
#include <nitro/math.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 Updates the seed's value
|
|
*/
|
|
void UpdateRandomValue() {
|
|
*(u64 *) this->mRandomValue = this->mAddend + (this->mFactor * this->GetRandomValue());
|
|
}
|
|
|
|
/**
|
|
* @brief Generates a random number as a u16
|
|
*/
|
|
u16 Next16() {
|
|
this->UpdateRandomValue();
|
|
return this->GetRandomValue() >> 48;
|
|
}
|
|
|
|
/**
|
|
* @brief Generates a random number from 0 (inclusive) to `max` (exclusive) as a u32
|
|
*/
|
|
u32 Next32(u64 min, u64 max) {
|
|
this->UpdateRandomValue();
|
|
return (((this->GetRandomValue() >> 32) * (max - min)) >> 32) + min;
|
|
}
|
|
|
|
u32 ConditionalNext32(u32 value) {
|
|
this->UpdateRandomValue();
|
|
|
|
u64 result = this->GetRandomValue() >> 32;
|
|
|
|
if (value != 0) {
|
|
result = (result * value) >> 32;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
void Init();
|
|
};
|
|
|
|
extern Random gRandom;
|