blob: 6f4f2ce55e2ec1829fa5c83c92e3202042c6524d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
#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 static u8 sUnknown = 0;
EWRAM_DATA static 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;
}
|