Add LocalRandomSeed (#4278)

This commit is contained in:
tertu 2024-03-16 14:55:01 -05:00 committed by GitHub
parent 7c25db5200
commit 7ac8aac913
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 0 deletions

View File

@ -17,6 +17,7 @@
* LocalRandom(*val) allows you to have local random states that are the same
* type as the global states regardless of HQ_RANDOM setting, which is useful
* if you want to be able to set them from or assign them to gRngValue.
* LocalRandomSeed(u32) returns a properly seeded rng_value_t.
*
* Random2_32() was added to HQ_RANDOM because the output of the generator is
* always 32 bits and Random()/Random2() are just wrappers in that mode. It is
@ -61,6 +62,7 @@ static inline u16 Random(void)
void SeedRng(u32 seed);
void SeedRng2(u32 seed);
rng_value_t LocalRandomSeed(u32 seed);
static inline u16 Random2(void)
{
@ -96,6 +98,11 @@ static inline void AdvanceRandom(void)
Random();
}
static inline rng_value_t LocalRandomSeed(u32 seed)
{
return seed;
}
#endif
extern rng_value_t gRngValue;

View File

@ -91,6 +91,13 @@ void SeedRng2(u32 seed)
SFC32_Seed(&gRng2Value, seed, STREAM2);
}
rng_value_t LocalRandomSeed(u32 seed)
{
rng_value_t result;
SFC32_Seed(&result, seed, STREAM1);
return result;
}
void AdvanceRandom(void)
{
if (sRngLoopUnlocked == TRUE)