Initiative is the primary factor in determining the order of attacks, not just unit to unit, but even from Primary and Extra attacks.
Stacks facing each other in battle with attacks of the same initiative will have their combat order determined randomly.