(crossposted from another forum)
This is a guide to how the game assigns equipment to human units when they have equipment slots set to random. It pertains primarily to human units in random battles (which is the inspiration for this guide) though many story battle opponents also have some or all of their gear determined by the routine the game uses.
Some credit goes to the folks at FFHactics for they provided the foundation for me to understand how this routine works (and some people there are aware of it already). I'll try to be as non-technical as possible so a non-hacker will be able to understand but some jargon will probably slip through.
In addition to the usual statistics of an item (WP, HP, MP, elemental and status resists, etc...) items also have some hidden attributes used in determining what a random human will equip.
Internal reference number: This is something the player never needs to know while playing the game but has a significant role in what a human unit might spawn with, which I will get into later. This is stored in hexadecimal in the game. I'll refer to it as item number or item ID as well.
Enemy Level: Named as such because it refers to the level an enemy must be at to start equipping the item. If a unit spawns at a level equal to or greater than the item's Enemy Level, it is considered allowed to equip the item (as long as the unit's class permits it, of course).
Finally, there's a bit that decides whether a randomly generated unit is allowed to equip an item at all. I'm not going to refer to this again in the guide; just mentioning it's existence. This is why non-storebought equipment (Ultimus Bow excepting) will not be found on random battle humans. (Germinas Peak chemists have rare guns because their weapon slot is set to fixed)
The Battle Mechanics Guide, among other sources, lists the item numbers as well as the other attributes listed above.
After all this, it's a surprisingly succinct routine. Equipment generation go by slot. Some units will have all their equipment slots set to random, like nearly all random battle humans. It's certainly possible to only have some equipment slots be random though (Orbonne Weigraf has random helm and armor only) or be entirely fixed (most boss opponents). For a given slot, the game will pick the item closest to or equal to the unit's level that the unit is able to equip and assign that item to the unit. If there are multiple items that have the same Enemy Level closest to the unit's level (Flame, Ice, Aegis Shield), the game will assign the one with the lowest item ID to the unit. This resolves all ties; the game only associates one item with the unit.
Any apparent randomness actually follows a consistent pattern. After an item has been assigned, the unit may equip any item it meets the level requirement for as long as the item has a higher item ID than the assigned item. Each eligible item appears to have an equal chance to appear but I haven't tried to gather more robust data. That's all there it to it. As an example, Mantles are at the end of the item list so there isn't something higher when the game decides to assign an Elf/Dracula/Feather mantle to a random battle opponent. But at 60 and above, the assigned accessory is the Bracer which has a lower item ID than most other accessories. So that Lv, 90+ Ninja one might be using to farm rare weapons can have nearly any accessory but not any boots, a Power Wrist, or Magic Gauntlet as their item IDs are lower than the Bracer's.
Trivia; Beowulf is the only player character to get his equipment assigned by the random routine. So at Lv 27 or 28, he'll always start with a Crystal Helmet. but only has a 50% chance at Lv 29 and above. Between Lv 31 and 36, he'll always start with a Black Robe. And so on.
I'll use Beowulf to demonstrate how the process works. For the sake of the example, he'll start at Lv 28
Weapon hand: Platimum Sword with it's E. Lv. of 28 is the closest match. Diamond Sword has an E. Lv. of 26 and a higher item ID so he will start with either. He won't start with a Knife because all Knives have a lower item ID than Swords.
Shield hand: Since Beowulf can equip Shields, the game will give him one. Diamond Shield will be assigned to him as its E. Lv of 25 is the closest without going over. Platina Shield has an E. Lv of 29 so he's not considered able to equip it even though it's closer than 25 to 28. There are no eligible Shields with a higher item number so the shield hand will always be the same at this level
Head: Crystal Helmet (27) Guaranteed for the same reason the Diamond Shield is in this example.
Body: Platina Armor (26) White Robe also has an E. Lv. of 26 but Platina Armor has the lower item ID so the game assigns him that. All robes have higher item numbers than armor so he may start with any robe the game indicates he can equip at that level. This is all the buyable ones up to White but never Chameleon Robe because it's not considered by the random routine.
Accessory: Diamond Armlet (26) Because of its placement on the item list, the only accessories he can begin with are the armlets, Small Mantle, and Leather Mantle.
Now if a unit is generated with Equip Crossbow or some other support ability that allows equipping some category of gear regardless of job, things change a bit. For weapons, it appears the unit is considered only able to equip crossbows, or axes, or whatever. The game will run the normal generation routine with this revised list. For Equip Armor, the game will run the routine as if the unit can only equip heavy armor but this appears to stack with the other assigned item if applicable. So that Lv 35 Knight with Equip Armor may show up with Carabini Mail or a Black Robe but doesn't appear to be able to wear any of the weaker robes. Equip Shield appears to prioritize a shield in the left hand but I'm not 100% certain since I lack data on how it interacts with Ninja's innate Two Swrods. Two Swords, incidentally, will always stick a weapon in the left hand and act as if the unit doesn't use shields.