1. Welcome to the Orange Islands! Please remember to read the rules. Come chat with us on our IRC channel and enjoy your stay!
  2. Welcome to Smogon Forums! Please take a minute to read the rules.
  3. Click here to ensure that you never miss a new SmogonU video upload!

Research Breeding RNG Quirk

Discussion in 'Sun and Moon' started by JuryRigging, Dec 10, 2016.

  1. JuryRigging

    JuryRigging

    Joined:
    Mar 12, 2016
    Messages:
    8
    My thread on another website wasn't getting much traction, so I thought I'd ask my question here. If this isn't the right place to ask a question like this, I apologize, and if you could please direct me to a place where my question would be relevant that would be great.

    Anyway, here goes:

    Something's fishy with the breeding RNG in this game.

    Some background; I'm MMing for a shiny Mimikyu. 40 boxes and still no shiny unfortunately. Out of sheer curiosity, I decided to test out if the breeding RNG in SM works the same why it did in XYORAS.

    In XYORAS, once the daycare man/lad has an egg, everything about it is set in stone (IVs, gender, shininess). If you save before taking the egg, hatch it, then reset and do it again, it'll be the same pokemon, no question.

    The catch is that after taking that egg, the NEXT egg generated will be random. For example, you take the first egg, hatch it, then take the second egg and hatch it. If you reset and do this process again, the second egg can have a different IV spread, gender, etc.

    I've been testing this in SM, and I've come across some weird results. When I save before the first egg, take it, then hatch it, it will be the same pokemon if I do this process over and over.

    HOWEVER, taking any subsequent eggs and hatching them is a different story. If you take the second egg and hatch it, then reset and take the first and second eggs and hatch them again, the second egg hatched will have the SAME IVs and gender as the second egg that was hatched before the reset! This happened with at least 3 other subsequent eggs, resetting about 3 times. It was very odd.

    I reset again, but this time I refused to take the first egg. I took the egg that was generated after that, and it naturally had a different IV spread than the egg I refused. But this is the WEIRD part. When I took the second egg, it still had the same IVs and gender as the second egg I took in any of the previous resets! Same goes for any subsequent eggs.

    Sorry for the long-winded mechanics anecdote, I just wanted to know if anyone else knew anything about this peculiarity.
    Dreamox, Edu, Pearl and 1 other person like this.
  2. Garris_san

    Garris_san

    Joined:
    Oct 31, 2016
    Messages:
    37
    Huh, seems like the time machine method is gone. I hadn't tested this myself, but for the sake of curiosity was one of those pokemon holding a destiny knot? Could have just been crazy rng. Unlikely as it is I appreciate as much detail as can be afforded. As to whether or not this is the right thread, I'm not sure to be honest.
  3. JuryRigging

    JuryRigging

    Joined:
    Mar 12, 2016
    Messages:
    8
    Yes, my 6IV Japanese Ditto was holding a Destiny Knot, and my Mimikyu was holding an Everstone. I tested something else just now, if that helps:

    I reset again, and rejected the first egg. Instead of generating a new egg right away, I took out Ditto and Mimikyu from the daycare, and put them back in, in a different order (Previously, Ditto was deposited first and then Mimikyu, so I reversed the order).

    Lo and behold, I achieved the exact same results for what happened in the last part of my original post, with the EXACT SAME IVs as the first Mimikyu after the rejected egg for the first egg generated in this test. The second, third, etc. Mimikyu were the exact same as any of the tests I had done previously.

    Now I'm testing for what would happen if I put a DIFFERENT Mimikyu but use the same Ditto to generate more eggs. I'll report back in a couple minutes.
  4. JuryRigging

    JuryRigging

    Joined:
    Mar 12, 2016
    Messages:
    8
    I'm back. I tried it with the two different Mimikyus. However this is only raising more questions than answers....

    I reset, reject the first egg as always. I take out the Mimikyu in the daycare and replace it with another Mimikyu. I generate and take 4 eggs after that exchange. The first two Mimikyu eggs are different, but then the last two ARE THE SAME AS ALL THE PREVIOUS TESTS.

    I'm starting to think there's some sort of broken RNG with eggs. Perhaps we can see the return of RNG Manipulation or something akin to Instacheck in the near future?
    Garris_san likes this.
  5. JuryRigging

    JuryRigging

    Joined:
    Mar 12, 2016
    Messages:
    8
    Good news! That thread I posted on the other website is getting more attention, and one user had a VERY interesting result regarding my situation:

    "I noticed this too.
    I was MMing for a shiny Dewpider. After hundreds of eggs, one hatched shiny but my 3DS died. Not that I minded since it wasn't the gender I wanted.

    I hadn't saved and went back to hatching eggs. Turns out the exact same shiny reappeared. Curious, I soft reseted and after a bunch of identical eggs, the same shiny showed up again.

    Then I changed the Dewpider in the nursery with another one: exact same result.
    I was trying to SR to change the gender but absolutely none of the eggs change.

    Since I didn't want a female Dewpider, I SR again and replaced the Dewpider in the nursery with a Mimikyu since I did want a female Mimikyu.
    Exact shiny hatched again (same nature, IV spread, even characteristic) but this time it was a Mimikyu.

    Though I didn't reject any eggs because I was lucky enough to save my game when the lady's sister didn't have any eggs to give me.
    It seems as if eggs are fixed no matter the parents."

    So even the species of Pokemon don't change the results, it seems.
  6. The Dutch Plumberjack

    The Dutch Plumberjack horyzhnz to horyzhnz
    is a member of the Site Staffis a Smogon Social Media Contributoris a Super Moderatoris a Contributor to Smogonis a Smogon Media Contributor
    Articles Co-Leader

    Joined:
    Jun 11, 2014
    Messages:
    3,598
  7. JuryRigging

    JuryRigging

    Joined:
    Mar 12, 2016
    Messages:
    8
  8. Ryin

    Ryin

    Joined:
    Dec 20, 2013
    Messages:
    5
    Based on what you wrote, what I believe to be happening is that, when the game rolls the RNG for eggs, it does it x eggs ahead.
    If it's like things were in gen VI (with a destiny knot equipped); for each egg it rolls it'll select 5 IVs from the parents and generate a random number for the 6th. So, supposing the game generates 10 eggs ahead: if you save your game, hatch 11 eggs, take note of the stats, and reset, the first 10 eggs you hatch will have the same combination of inherited IVs as the ones you hatched before and the 11th one will be a new combination.
    If this is the case, what we have to determine is how many eggs ahead the game generates.
    Having detailed IV info for the parents and offspring would be very helpful for this.
    I don't have my 3DS with me this weekend, so I can't help testing for now.

    Why do you think a guy trying to understand how breeding RNG works should post in a "simple questions" thread?
    Carrier and Vinc2612 like this.
  9. JuryRigging

    JuryRigging

    Joined:
    Mar 12, 2016
    Messages:
    8
    Hi friend, thanks for replying. It looks like changing which parent holds the Destiny Knot will change the 'egg list' so to speak. If you want my full findings you can go here: http://boards.4chan.org/vp/thread/30676572
    Mind the profanity and the negative talk about the mod in that thread, 4chan tends to be rather reactive. I'm sure the mod just didn't understand what I was asking and was trying to be helpful, all-in-all.
    Last edited: Dec 10, 2016
  10. viperGTS

    viperGTS

    Joined:
    Nov 1, 2008
    Messages:
    1,368
    I am encountering this too. I posted in the Wi-Fi SQSA thread too, but I'll read your 4chan post since it seems to have more traction.

    IMO, this will get drowned in that thread relatively quickly. This deserves its own thread.
  11. Siggu

    Siggu

    Joined:
    Sep 22, 2010
    Messages:
    2,102
    This looks like it can exploited to a certain extent.

    Put two parents with great IVs. The game will roll for the IVs and Natures.

    Reject the first egg, then change the parents so that you can get a baby of a species you don't have parents with good IVs.

    Voila! Baby with great IVs without even trying.

    BTW, would this work with genders as well? This could be AWESOME in terms of breeding Salandit or Combee.

    This could also be interesting for ability slots, if possible.

    Waitwaitwait... if it also happens with Ability Slots... could we get babies with Hidden Abilities if the game rolled for Hidden Ability slots even if the parents lack it?

    (For example -which is what I'm gonna try when I get back home-, get a Rough Skin Gible and a Ditto. Check eggs to see which baby gets Rough Skin. Swap Gible with, say, a Rowlet. Can the hatchlings get Long Reach with this quirk?)
    Last edited: Dec 14, 2016
  12. Viridi

    Viridi

    Joined:
    Jul 29, 2014
    Messages:
    1,457
    Seconding your question. However, I would also like to add to it. For example, if this method were possible and I hatched a Liquid Voice Popplio using this method, would it be legal to trade here?
  13. Siggu

    Siggu

    Joined:
    Sep 22, 2010
    Messages:
    2,102
    Also, ball inheritance should be checked here. Some illegal ball combinations may be able to be obtained if it is also kept after switching parents.
  14. MKL122788

    MKL122788

    Joined:
    Oct 12, 2013
    Messages:
    444
    So, judging from what was discovered, this is what seems to be pre-determined:

    Personality(can be overwritten by Everstone)
    Shiny ID
    IV contribution(To some extent. Whether it is locked in or based on Male Parent Providing XYZ and Female Parent Providing ABC needs to be established. It could also be Parent with Destiny Knot passes down XYZ, parent without passes down ABC.)
    Gender Roll(Whether it is the number out of 256 or the gender itself)
    Ball contribution(Whether it is set as Female or Male or Male and Override if different species.)
    Ability Dice Roll(Whether a HA can be acquired illegitimately.)

    Here is my guess based on the reading:

    Personality is 100% predetermined a certain number of Eggs into the future.
    Shiny ID is 100% predetermined a certain number of Eggs into the future.
    Gender *ROLL* is 100% predetermined a certain number of Eggs into the future. This means that if you roll a 128 of 256(for example), a Cleffa will be female, but a Popplio will be male.

    Destiny Knot being removed resets table likely because it takes 5IV inheritance assumptions and is forced to change it to 3IV inheritence assumptions.

    So what tests need to be run? Simple, let a 6IV Pokemon who is male hold the destiny knot and breed with a Ditto with no perfect IVs. In that scenario, Ditto acts as the male. See what the offspring inherit. Now, swap it out for a mother with 0 perfect IVs. See if the same stats are inherited.

    If the same things are inherited from each parent, then the destiny knot holder is the determining factor. If the opposite things are inherited with the same roll on the last stat, then the "acting gender" is the determining factor for IV pre-roll inheritence. If it is something else entirely, then the nuance continues and it is likely neither.

    The other question is how long the number of Eggs into the future is. Is it a looped, repeating list that goes on forever? Or is it a finite listing?

    I will do my best to help with these questions.

    EDIT:

    Going through that thread, this pastebin was linked.

    http://pastebin.com/4Gp9Esm9

    The indication in this is that switching egg groups can *possibly* switch whether Ditto is acting as Parent A or Parent B, which could indicate gender role.

    The assumption was Ditto is always acting as the "male" pokemon, but it may not always be the case.
    Last edited: Dec 14, 2016
  15. zomigi

    zomigi

    Joined:
    Jul 18, 2010
    Messages:
    8
    Blastoise_X figured out how egg generation works, see http://blastoise-x.hatenablog.com/entry/SM-breed (in Japanese).

    Here's how egg generation works as far as I can tell from the above post and the disassembly of the breeding method from the demo:

    Roll one RN each for gender/nature/ability, skip the gender roll if genderless/fixed-gender. In the case of Nidoran or Volbeat/Illumise, roll for offspring species before anything else. If both parents hold everstone, roll to determine which nature is inherited.
    If parents have matching power items, roll to determine which to inherit from the initial roll for nature. Note that nature will always be rolled for regardless of whether the parents hold everstones.
    Roll an RN to get a stat (HP, Atk, Def, etc.). If it hasn't been set to be inherited yet, roll another RN to determine which parent it will be inherited from, otherwise ignore it. Repeat until enough different stats have been set to be inherited (5 with destiny knot, 3 without).
    Now roll one RN for each stat (so roll 6 RNs), which is the random IV it gets if it wasn't inherited.
    Roll 1 RN for encryption constant.
    Re-roll RNs for PID and check for shininess twice if you have shiny charm. Roll 6 more RNs and check for shininess if using Masuda method. Do not continue rolling if any PID would be shiny. Initial PID is drawn from a different source, presumably the main game RNG, and it is not checked for shininess before being rerolled if any rerolls are available.
    If parents are same species, roll 1 RN for ball inheritance.
    Roll 2 more RNs for ???. These are not in the disassembly, and I don't know what they're used for. Based on checking eggs' gender/nature/ability/IVs/encryption constant/PID, I am reasonably sure these occur at the end, though I haven't tested anything other than different species Masuda method parents with shiny charm and destiny knot.

    Some other notes:
    Rejecting eggs consumes 1 RN.
    To go from gendered to genderless, reject one egg before you accept each egg of the genderless 'mon.
    If you want to preserve the sequence, when going from same species+gendered to different species+gendered, reject one egg after accepting each egg from the different species+gendered pair.

    As far as anyone knows, egg RNG appears to be independent of everything else.
    The RNs are generated via TinyMT, for more on finding the RNG state see this post (in Japanese), which also has a calculator to find the state given the least significant bits of 127 successive RNs, though this would require a good deal of resetting, rejecting, and hatching. To get the least significant bit, check the offspring of a Nido/Illumise/Volbeat, check nature with two everstone parents, or check IVs with matching power item parents.

    edit: made some corrections in light of further developments in the thread and seeing the disassembly.

    edit2: added mystery 2 RNs at end.
    Last edited: Dec 18, 2016
    Zowayix likes this.
  16. DougJustDoug

    DougJustDoug Knows the great enthusiasms
    is a member of the Site Staffis an Artistis a Programmeris a CAP Contributoris an Administratoris a Battle Server Admin Alumnusis a Live Chat Contributor Alumnusis a Tiering Contributor Alumnus
    CAP Leader

    Joined:
    Jun 26, 2007
    Messages:
    3,538
    So this could really speed up breeding, if the egg RNG is not used by anything else and generates the same random number sequence regardless of species in daycare. You could speed-breed a fast hatching pokemon like Magikarp until you get a really good set of IV's, saving periodically as you go through breeding spitbacks. Then when the good IV's are "queued up", switch the parents to the slower-hatching Pokemon you really want. Then only suffer for a few slow hatching eggs to get great IV's.

    I've always loved breeding Gyarados, because the hatching times are so fast for Magikarp (a mere 1280 steps base). Meanwhile, breeding a Dragonite is like pulling teeth, with those long 10,000+ step base hatching cycles. This method could make all Pokemon breeding projects much, much faster, if I'm reading this correctly.
  17. Siggu

    Siggu

    Joined:
    Sep 22, 2010
    Messages:
    2,102
    I've made some tries on my own.

    Started with Rough Skin Jolly Gible (hatchling with Outrage) on a Dusk Ball + 4IV Ditto.

    Then, I switched the Gible with an Overgrow Timid Snivy on an Ultra Ball. Three different times - itemless, with an Everstone, and with a Destiny Knot.

    These were my findings (possible errors while trying notwithstanding):
    - Apparently, the Ability and Ball dice rolls cannot give you an Ability or Pokeball that is in neither inheritable parent. The game seems to roll for "Ability of the mother/non-Ditto vs. an Ability that is not the mother/non-Ditto's" (Instead of "Ability of the slot of the mother/non-Ditto's vs. Ability that is not of the slot of the mother/non-Ditto's"), and same with Balls. This meant, all Snivy, in each different try, had Overgrow and an Ultra Ball instead of Contrary ( :( ) and a Dusk Ball, even though the initial parent had the Hidden Ability slot and a Dusk Ball.
    - Everstones have no effect on the rolls. While rolling with an Everstone, the babies had the same natures as the baby Gibles, except the first one, which was Timid, just like the parent with the Everstone. Unless I actually forgot to give the Everstone to the Snivy >.<
    - There were IV differences, as the above posts suggest, but the Natures had no differences until Destiny Knot messed up with the RNG sequence.

    It could be worth checking Egg Moves as well. Whether the baby can end up with the original parents' moves.
    Last edited: Dec 14, 2016
  18. ΩDonut

    ΩDonut don't glaze me bro
    is a Pokemon Researcheris a Programmer Alumnusis a Forum Moderator Alumnusis a Contributor Alumnus

    Joined:
    Aug 23, 2006
    Messages:
    3,741
    Just FYI, this egg RNG cannot be exploited for shininess. Almost every aspect of the egg - base IVs, parent IV inheritance, nature, ability, encryption constant - is determined by this RNG, but the PID for shininess is pulled from the game's main RNG (a currently uncontrollable Mersenne Twister) at the time of the egg's creation.
    Trinitrotoluene likes this.
  19. zomigi

    zomigi

    Joined:
    Jul 18, 2010
    Messages:
    8
    No, the RNs used for shininess are pulled from the same TinyMT as everything else from the egg.
  20. ΩDonut

    ΩDonut don't glaze me bro
    is a Pokemon Researcheris a Programmer Alumnusis a Forum Moderator Alumnusis a Contributor Alumnus

    Joined:
    Aug 23, 2006
    Messages:
    3,741
    They are not. I verified this by obtaining the egg, then reverting to an earlier copy of the save file where I hadn't picked up the egg and picked it up again. Every aspect of the egg was identical EXCEPT for the PID which is used to determine shininess.

    That does seem at odds with the shiny result mentioned earlier in this thread though.

    p.s. I've been working on this egg RNG research since before the Japanese researchers made their info public, although I didn't have the math chops to come up with the seed reversing equation their tool uses. https://twitter.com/pokemon_PhD/status/804245701119143936
  21. zero2exe

    zero2exe Veteran Breeder - Expert Translator
    is a Contributor Alumnus

    Joined:
    Jan 7, 2010
    Messages:
    1,008
    Do you all know that most of this stuff has already been covered in 6th gen by the .com's time machine guide?
    http://www.smogon.com/forums/members/com.38797/ (check signature)
    The only real changes this gen I can see so far are:
    1.- Instead of the "next egg" being pre-determined alone, now the game pre-determines a whole batch of eggs ahead (more than 30 and counting), so you can no longer just reject the egg to re-roll for another one.
    2.- Since the male parent can inherit their pokeball now this also created a new branch of RNG which is achieved when you have 2 parents of the same species with a different ball, which have their own separate list of pre-determined eggs.
    3.- We now have 3 sources of egg RNG:
    i.- The Genderless/100% ratio parents
    ii.- The 12.5%/25%/50% Gender ratio parents with different species of pokemon (ie. ditto)
    iii.- The same 12.5%/25%/50% Gender ratio parents that use the same species of pokemon but have different ball
    There could be more depending if the "same species but with identical balls" goes into the 2nd or 3rd group which I haven't tested yet.

    This is just a guess so far, but I think that the main RNG you mention is actually tied to your current save, but remains constant as long as you don't save again at another point.
    There's been reports that you can actually make the same egg hatch shiny as long as you keep using the same kind of parents (ball RNG and gender ratio RNG iirc), sadly I couldn't pull this myself because I made the mistake of saving again during the process, which makes me believe that it's tied to the save file itself unlike the other components.
    Kadabrium likes this.
  22. Kadabrium

    Kadabrium

    Joined:
    Jan 13, 2013
    Messages:
    558
    Just if anyone hasnt figured, RNG calls are expected to change also if you change everstones/power items/destiny knot, so they should be kept constant when you discover a shiny slot and reset.
  23. zomigi

    zomigi

    Joined:
    Jul 18, 2010
    Messages:
    8
    I just tried this and got the same PID each time, which matches up with what the Japanese researchers have claimed and what people across the internet have been reporting.

    Also, looking at the breeding method disassembly from the demo, the call to generate the PID uses what appears to be the TinyMT state as an input. In fact, everything the Japanese researchers found appears to agree with that disassembly, including the fact that the Masuda method has been buffed this generation.
  24. ΩDonut

    ΩDonut don't glaze me bro
    is a Pokemon Researcheris a Programmer Alumnusis a Forum Moderator Alumnusis a Contributor Alumnus

    Joined:
    Aug 23, 2006
    Messages:
    3,741
    Nope, I got different PIDs.

    upload_2016-12-15_0-52-59.png

    identical IVs

    upload_2016-12-15_0-54-8.png

    identical encryption constant, though.

    upload_2016-12-15_0-54-55.png
    The Idealistic likes this.
  25. ΩDonut

    ΩDonut don't glaze me bro
    is a Pokemon Researcheris a Programmer Alumnusis a Forum Moderator Alumnusis a Contributor Alumnus

    Joined:
    Aug 23, 2006
    Messages:
    3,741
    Looking at the disassembly, you can see that the PID rerolls are generated by a different function, sub_296154, not a call to gfl2::math::Random::Next as is used for all the other egg values. Although it does look like sub_296154 is a second TinyMT, so I guess I was wrong about it using the game's main Mersenne Twister. Remains to be seen whether it can be manipulated or not.

    Code:
    int __fastcall sub_296154(int a1)
    {
      int v1; // r3@1
      int v2; // r2@1
      int v3; // r5@1
      int v4; // r1@1
      int v5; // r6@1
      int v6; // r12@1
      unsigned int v7; // r2@1
    
      v1 = *(_DWORD *)(a1 + 4);
      v2 = *(_DWORD *)(a1 + 8);
      v3 = *(_DWORD *)a1 & 0x7FFFFFFF ^ v1 ^ v2 ^ 2 * (*(_DWORD *)a1 & 0x7FFFFFFF ^ v1 ^ v2);
      v4 = *(_DWORD *)(a1 + 12) ^ v3 ^ (*(_DWORD *)(a1 + 12) >> 1);
      v5 = -(v4 & 1);
      v6 = *(_DWORD *)(a1 + 16) & v5 ^ v2;
      v7 = *(_DWORD *)(a1 + 20) & v5 ^ v3 ^ (v4 << 10);
      *(_DWORD *)(a1 + 12) = v4;
      *(_DWORD *)(a1 + 8) = v7;
      *(_DWORD *)a1 = v1;
      *(_DWORD *)(a1 + 4) = v6;
      return (v1 + (v7 >> 8)) ^ v4 ^ -((v1 + (v7 >> 8)) & 1) & *(_DWORD *)(a1 + 24);
    }
    
    vs. the TinyMT function used for all other egg values

    Code:
    unsigned int __fastcall gfl2::math::Random::Next(gfl2::math::Random *this, unsigned int a2)
    {
      int v2; // r12@1
      int v3; // r3@1
      int v4; // r5@1
      int v5; // r2@1
      int v6; // r6@1
      int v7; // r5@1
      int v8; // r4@1
      int v9; // lr@1
    
      v2 = *((_DWORD *)this + 1);
      v3 = *((_DWORD *)this + 2);
      v4 = *(_DWORD *)this & 0x7FFFFFFF ^ v2 ^ v3 ^ 2 * (*(_DWORD *)this & 0x7FFFFFFF ^ v2 ^ v3);
      v5 = *((_DWORD *)this + 3) ^ v4 ^ (*((_DWORD *)this + 3) >> 1);
      v6 = -(v5 & 1);
      v7 = v4 ^ (v5 << 10);
      v8 = *((_DWORD *)this + 5) & v6;
      v9 = *((_DWORD *)this + 4) & v6 ^ v3;
      *((_DWORD *)this + 3) = v5;
      *((_DWORD *)this + 2) = v8 ^ v7;
      *(_DWORD *)this = v2;
      *((_DWORD *)this + 1) = v9;
      return ((v2 + ((v8 ^ (unsigned int)v7) >> 8)) ^ v5 ^ -((v2 + ((v8 ^ (unsigned int)v7) >> 8)) & 1) & *((_DWORD *)this + 6))
           % a2;
    }
    
    Last edited: Dec 15, 2016
    The Idealistic likes this.

Users Viewing Thread (Users: 0, Guests: 0)