a table is an array of 624 numbers, called t[0..623], normally indexed with nlet's start with the 0th table construction
So initial_table can be generated with only SEED as input.t[0] = Initial SEED
t[n] = (( upper 2bits of t [n-1] ) xor t [n-1]) * 0x6c078965 + n
k[0] , k[1]
k[0] = (t[A] and 0x80000000) or (t and 0x7fffffff)
k[1] = (k[0]/2) and t[C]
small mistype here: last line should end with "for n=623", right?where
A=n B=n+1 C=n+397 for 0 < = n < = 226
A=n B=n+1 C=n-227 for 227< = n < = 622
A=n B=0 C=396 for n = 632
and t[A],t,t[C] refer to the elements of the 0th table
Only previous table is needed, although k0 and k1 are used, they are calculated with the iterator.the elements of the new table are formede as follows
I am very much puzzled by the "can be chosen at free will". If it's any relevance in the DS game, we should now where it is taken from. If it's of no relevance, then it's not really needed.In the end a total of M tables are formed (M can be choosen at free will)
This very much looks like "first, table1 is cycled completely, then table2 is cycled completely, then table3..."the IRNG is then formed as : S[(m-1)*624+n] = t[n] of the mth table
and then the PID is formed by taking the "random" number (E) and doing some more calculation.when the seed in the IRN is designated as E ( E = S(indices))
the PID is formed by means of an auxiliary 32 bit variable K[n] , n = 0,1,2; as follows
To be honest, some of the pseudo-programming syntax more confused than clear things. You're writing arrays for simple temporary results; square braces as function parameters...(I used a pseudo-programming syntax for better explaining)
D/P is not really "broken. It's just that it can be figured out.So even D/P is broken like this? That's very interesting. After Emerald's broken RNG was discovered was D/P not checked? Are their seed generators similar? I doubt I'm using the right lingo for that last sentence...but hey, I'm trying to familiarize myself with it.
Seems like as soon as someone tells he looks into gamecode, suddenly many tasks arise that should be done. Mingot already wants me to figure out the synchro-pid-generation on chained shinys, I want to know more about the eggs and memory location. I have to agree that ID+SecretID would be very useful to know.-TCCPhreak. Are you looking into the game code? If yes could you check how the ID and the Secret ID are created? maybe we can work out how to calculate the Secret ID from the ID and the game starting date...It would be awesome.
english Wikipedia describes it as complicated as I can imagine, jonny's pseudocode seemd much more easier to understand. Also I sort of like it when I know the code in my tools by heart.Not to discourage you from writing your own code, but it's a Mersenne Twister and if you google that you can find sample code x 2 in every language you could imagine. Also google has pretty clear pseudo code for re-implementing.
uint initialSeed = 0U;
// Our builder table.
uint[] t = new uint[624];
t[0] = initialSeed;
for (uint cnt = 1; cnt < 624; cnt++)
{
t[cnt] = (0x6c078965 * (t[cnt - 1] ^ (t[cnt - 1] >> 30))) + cnt;
}
// Start building out the S table, which we are going
// to number with how many results we have. Currently
// we will build multiples of these based on how many
// results we want to return.
uint[] a = new uint[624];
uint[] b = new uint[624];
uint[] c = new uint[624];
for (uint n = 0; n < 624; n++)
{
a[n] = n;
if (n <= 226)
{
b[n] = n + 1;
c[n] = n + 397;
}
else
{
if (n <= 622)
{
b[n] = n + 1;
c[n] = n - 227;
}
else
{
b[n] = 0;
c[n] = 396;
}
}
}
uint[] d = new uint[624];
for (uint n = 0; n < 624; n++)
{
uint k0 = (t[a[n]] & 0x80000000) + (t[b[n]] & 0x7fffffff);
uint k1 = (k0 / 2) ^ t[c[n]];
if (k0 % 2 == 0)
{
// Even
d[n] = k1;
}
else
{
// Odd
d[n] = k1 ^ 0x9908b0df;
}
}
for (uint n = 0; n < 10; n++)
{
uint p = d[n];
p = p ^ (p >> 11);
p = p ^ ((p << 7) & 0x9D2C5680U);
p = p ^ ((p << 15) & 0xefc60000U);
p = p ^ (p >> 18);
Console.WriteLine(p.ToString("x"));
}
the Jonny2Code has at least 2 mistakes: an | must be replaced with a + and a & with a xor somewhere but I don't remember where...time has passed :D.Found something that looks more friendly on german wiki, gotta try that - because my "jonny-2-code"-try didn't work.
TCC
At first ARNG was for Another RNG, but it seems now they are using it for Alternate RNG: http://projectpokemon.org/wiki/Notable_BreakpointsSo why are you calling it the ARNG? (Alternate?)
If this is what is used for mystery gift Pokemon then you have stumbled on something very interesting. Any documentation on this anywhere?
Hey, tsanth, I have done some research regarding the generation of mystery gift pokemon.
Here is an article regarding the confirmation that they cannot be shiny: http://db.pokesav.org/main/?q=11-29-08-Mystery-Gift-PKMN-Cannot-Be-Shiny
For a bit of more technical data:
0x201BA10 -- Another RNG.
0x2068AAC -- Shiny Check for mystery gift pokemon
The seed for this RNG at 0x201BA10 is obtained from the half-words at 0x4000100 and 0x21D37B4.
Those two values are not related at all to the value of the seed for usual PRNG.
The value of the seed for the usual PRNG is used for the IVs as usual.
Link to how emerald runs for eggs?Man, the code for the IRNG was anything but convenient to sort out. Honestly, I think with that the goal was to actually make it harder. Even emerald runs differently for eggs.
If you mean the PID generation for eggs, SCV worked on it a while ago. You should ask him.Link to how emerald runs for eggs?
My guess is he did not know it was used for eggs as well. I actually already know what he told Wichu and for emerald it was a seemingly similar proccess. I was just curious as to what you meant by different. Except in that case it was two instances of the same RNG, whearas here there are at least two RNGs.A few people here (Wichu/Pink) asked him to look into the Egg RNG a while back (as in a week or so ago) and he said he would look into it and not that it was already documented as this ARNG. So I dunno, I guess I will see if I can get in touch with him about it.
The seed for this RNG at 0x201BA10 is obtained from the half-words at 0x4000100 and 0x21D37B4.
Well maybe the people who re-discovered this RNG have not gone as far SCV did. He figured out exactly where the seed comes from and where it goes since Sabresite was hoping there could be a legality check for mystery gift pokemon.This seems a little strange, though, as the MT does not have a simple seed that you can store in 32 bits.
One thing that is very interesting is his Shiny Prevention article mentions the Shiny check bug for hatches, as they test with the old OT and this is pretty much the same bug making things not look shiny on hatch. Always nice when observations line up.
Well then, what happens is that the seed in not obtained in the same way in each case. Now, that I think about it, the seed for the marsh pokemon and swarm route is stored in the save.Er, but that's just the thing. MT is seeded one time only, it's not perpetually fed a seed (nor does it have a location where it need to 'store' its seed) on each iteration as the LCRNG. It actually has to build a table of 624 words.
It could be the location of the initial seed (same as the one used for the LCRNG) but then in that case it would never need to change.
Was that in DP or platinum?@ hrc969
Ok, I went to the memory location listed @ 0201BA10 and described as "Alternate RNG used in some cases: Examples, PID generation for mystery gift pokemon, recalculating a PID after a failed shiny check, number which determines swarm pokemon and great marsh pokemon"
It is definately NOT the IRNG.
This routine is used, though, as part of the breeding process for international parents to alter pids to increase the chance of it being shiny.
Here is what it looks like in my code:
pid = pid * 0x6c078965 + 1;
It's basically another implementation of an LCRNG, I believe, with a different multiplier and increment.
It really looks like they might be calling the routine from a different entry point (or more likely have two implementations of this) one for just using r0 and applying the multiply and add and another for taking a seed for it.
Either way, these are not the droids you are looking for.
OK, thanks for clearing that up.@ hrc969 - I just did it in DP using the offset listed for DP for the ARNG. The offset for Platinum is simply the same routine at a new offset, I would think.
I used your Notable Breakpoints page to go look at the assembly for the routine.
It was definately x = x * 0x6c078965 + 1;
Which is definately NOT the IRNG.
So three RNGs.
I really can't be assed to go find the breakpoint for the IRNG as I already understand what it does, but someone who wants to see if it is used for anything other than egg PID generation might be interested in doing so.