2017-04-23 16:18:42 +00:00
|
|
|
|
namespace PKHeX.Core
|
|
|
|
|
{
|
|
|
|
|
public class RNG
|
|
|
|
|
{
|
2017-04-23 19:07:45 +00:00
|
|
|
|
public static readonly RNG LCRNG = new RNG(0x41C64E6D, 0x00006073, 0xEEB9EB65, 0x0A3561A1);
|
|
|
|
|
public static readonly RNG XDRNG = new RNG(0x000343FD, 0x00269EC3, 0xB9B33155, 0xA170F641);
|
|
|
|
|
public static readonly RNG ARNG = new RNG(0x6C078965, 0x00000001, 0x9638806D, 0x69C77F93);
|
2017-04-23 16:18:42 +00:00
|
|
|
|
|
|
|
|
|
private readonly uint Mult, Add, rMult, rAdd;
|
2017-04-29 23:22:32 +00:00
|
|
|
|
private RNG(uint f_mult, uint f_add, uint r_mult, uint r_add)
|
2017-04-23 16:18:42 +00:00
|
|
|
|
{
|
|
|
|
|
Mult = f_mult;
|
|
|
|
|
Add = f_add;
|
|
|
|
|
rMult = r_mult;
|
|
|
|
|
rAdd = r_add;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public uint Next(uint seed) => seed * Mult + Add;
|
2017-04-29 23:22:32 +00:00
|
|
|
|
public uint Prev(uint seed) => seed * rMult + rAdd;
|
2017-04-23 16:18:42 +00:00
|
|
|
|
|
2017-04-29 23:22:32 +00:00
|
|
|
|
public uint Advance(uint seed, int frames)
|
2017-04-23 16:18:42 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < frames; i++)
|
|
|
|
|
seed = Next(seed);
|
|
|
|
|
return seed;
|
|
|
|
|
}
|
2017-04-29 23:22:32 +00:00
|
|
|
|
public uint Reverse(uint seed, int frames)
|
2017-04-23 16:18:42 +00:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < frames; i++)
|
|
|
|
|
seed = Prev(seed);
|
|
|
|
|
return seed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|