There is likely randomness within each grouping indeed but the order of appearance of the groups, PCIe Slots -> Optical Drive Ports -> SATA Bays, has always been the same for me. Unless a fluke of course.
As to what gets booted, remember that Intel Macs follows the UEFI spec (in spirit if not in intent)
- Boot the bootloader in the location saved in the NVRAM
- Saving to NVRAM on Mac is by "systemsetup -setstartupdisk" or by "bless" (Deprecated)
- If nothing is found in the NVRAM, such as after resetting this or the file is not present or the disk has failed, initiate a UEFI fallback search.
- Boot the first UEFI fallback bootloader found in a UEFI fallback bootloader location (/EFI/Boot)
- Once such a file is found using the "PCIe Slots -> Optical Drive Ports -> SATA Bays" search pattern, AFAICS, it is booted.
- This is where UEFI Windows can get booted inadvertently
- In a default Mac setup, all "/EFI/Boot" folders are always empty (do not exist) of course.
- If a UEFI fallback bootloader is not found, initiate a Mac OS fallback search.
- If nothing is found, the default Mac OS setup, Intel Mac then goes off on a tangent and extends the UEFI Spec
- Boot the first Mac bootloader found in a Mac OS default bootloader location (/System/Library/CoreServices)
- Once such a file is found using the "PCIe Slots -> Optical Drive Ports -> SATA Bays" search pattern, AFAICS, it is booted.
My natively supported Mac OS version is on the Optical Drive Port and clearing the NVRAM results in it getting booted without fail (if there isn't a fallback bootloader in play). When I attach similar to a PCIe Slot, that gets booted instead when nothing is blessed and a fallback bootloader is absent. I always have a fallback bootloader, RefindPlus, in play these days so testing basically stopped.
As an aside, on the SATA Bays, I am not so sure the belief that the SATA Bays are processed in order (Bay 1 to 4) is actually correct. Haven't tested fully, but I think the order may actually be random based on the Disk ID allocated to each disk (/dev/disksX) which as we know, is not fixed. Haven't tested in full though.
Either way, once a SATA bay is selected, the specific volume on the disk to boot, which can be more than one, then needs to be selected. How is this done? I think by Disk ID but not verified as mentioned.
EDIT:
Missed out that the last booted Mac OS version stored in the NVRAM comes into play somewhere in the mix, when present. Haven't dived into this properly.