mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-11-18 04:27:38 +01:00
36 lines
585 B
C
36 lines
585 B
C
|
#include "global.h"
|
||
|
#include "rng.h"
|
||
|
|
||
|
// The number 1103515245 comes from the example implementation of rand and srand
|
||
|
// in the ISO C standard.
|
||
|
|
||
|
extern u32 gRngValue;
|
||
|
extern u32 gRng2Value;
|
||
|
|
||
|
EWRAM_DATA u8 sUnknown = 0;
|
||
|
EWRAM_DATA u32 sRandCount = 0;
|
||
|
|
||
|
u16 Random()
|
||
|
{
|
||
|
gRngValue = 1103515245 * gRngValue + 24691;
|
||
|
sRandCount++;
|
||
|
return gRngValue >> 16;
|
||
|
}
|
||
|
|
||
|
void SeedRng(u16 seed)
|
||
|
{
|
||
|
gRngValue = seed;
|
||
|
sUnknown = 0;
|
||
|
}
|
||
|
|
||
|
void SeedRng2(u16 seed)
|
||
|
{
|
||
|
gRng2Value = seed;
|
||
|
}
|
||
|
|
||
|
u16 Random2(void)
|
||
|
{
|
||
|
gRng2Value = 1103515245 * gRng2Value + 24691;
|
||
|
return gRng2Value >> 16;
|
||
|
}
|