pokeemerald/src/random.c
2018-04-29 14:21:59 +02:00

37 lines
630 B
C

#include "global.h"
#include "random.h"
// The number 1103515245 comes from the example implementation of rand and srand
// in the ISO C standard.
EWRAM_DATA static u8 sUnknown = 0;
EWRAM_DATA static u32 sRandCount = 0;
// IWRAM common
IWRAM_DATA u32 gRngValue;
IWRAM_DATA u32 gRng2Value;
u16 Random(void)
{
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;
}