2017-02-03 01:30:08 +01:00
|
|
|
#include "global.h"
|
2017-12-05 19:27:33 +01:00
|
|
|
#include "random.h"
|
2017-02-03 01:30:08 +01:00
|
|
|
|
|
|
|
// The number 1103515245 comes from the example implementation of rand and srand
|
|
|
|
// in the ISO C standard.
|
|
|
|
|
2017-02-03 18:32:51 +01:00
|
|
|
EWRAM_DATA static u8 sUnknown = 0;
|
|
|
|
EWRAM_DATA static u32 sRandCount = 0;
|
2017-02-03 01:30:08 +01:00
|
|
|
|
2018-04-29 14:21:59 +02:00
|
|
|
// IWRAM common
|
|
|
|
IWRAM_DATA u32 gRngValue;
|
|
|
|
IWRAM_DATA u32 gRng2Value;
|
|
|
|
|
2017-09-08 18:28:00 +02:00
|
|
|
u16 Random(void)
|
2017-02-03 01:30:08 +01:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|