Jump to content

Desert Item RNG mechanics


JudgeWargrave
 Share

Recommended Posts

The mechanics of the main RNG in the GBA games is fairly easy to find, and the reset trick to get the desert items with the secondary RNG is also quite well known or at least searchable, but the actual mechanics of that RNG were something I had a hard time finding online, so I figured I would post my findings here for anyone interested. It's mostly just academic value, but it allows you to dig up the items without resetting so it has some value in saving time. I believe the system works the same in FE6 but I haven't tested it. FE8 uses the primary RNG and the unit's luck stat so none of this applies to FE8.

The seeds for the primary RNG are located at memory location 0x03000000 as three 2-byte numbers. The secondary RNG is located at 0x03000008 and is 4 bytes long. The function to generate the next number from the previous one is

local function nextrng2(generator)
	local lowerWord = AND(generator, 0x0000FFFF)
	local upperWord = AND(generator, 0xFFFF0000)/0x10000

	local lowerPart = 4*lowerWord*lowerWord+5*lowerWord+1
	local upperPart = upperWord*(5+8*lowerWord)*0x10000
	
	return AND(lowerPart+upperPart,0x3FFFFFFF)
end

In words, it splits the previous number into upper and lower bytes, applies some formulas, pieces them back together, then sets the first two bits to zero (i.e. ANDs with 0x3FFFFFFF; the full 32 bits aren't used but rather 30 bits).

I figured this out with the help of this page and google translate. Of course, that wasn't totally clear, but by editing the values at 0x03000008 directly and observing the output I was able to get to the function.

Now, when is this function called, and how is it used to check for digging up items? The main time it seems to be called, other than the desert item check (1 call), is whenever a unit's large portrait is loaded. This pops up when a unit initiates combat (2 calls), when you look at their inventory (2 calls), when you initiate a trade (4 calls), and when Anna blinks on the suspend menu (1 call). Of course, it is not called during combat or by pathfinding/arrow drawing. IIRC it is called many times during the critical hit animation, so watch out for that.

It checks for desert item by taking the number modulo 11. If the remainder is 0, the dig is a success, thus the probability of 1/11 ~= 9.09%.

You can see this technique demonstrated in this video: I open Dart's item menu 3 times to advance the secondary RN and make Florina dig up the Filla's Might. https://youtu.be/cZPttktS1qI?t=4m31s

Edited by JudgeWargrave
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...