Skip to content

Commit

Permalink
Add LocalRandomSeed (#4278)
Browse files Browse the repository at this point in the history
  • Loading branch information
tertu-m authored Mar 16, 2024
1 parent 7c25db5 commit 7ac8aac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/random.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions src/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7ac8aac

Please sign in to comment.