It is only a random roll in so far as the combat result has a random element.
1) Infantry will try to fall back from infantry if they lose the round of combat "badly". Unfortunately it isn't possible to quantify what constitutes "losing the combat round badly" in a way that would be comprehensible to the player, as it is all tied up with intermediate values used during the resolution of close combat.
It isn't directly related to casualties, although you can see that in this case the losing side did suffer much higher casualties than the winners. The casualties are in fact adjusted after deciding who is losing, and how badly, rather than the other way round. This is because in Ancient warfare, casualties increased as a result of a unit giving way, rather than the unit giving way primarily as a result of casualties.
If the unit is fighting enemy Shock infantry who originally charged them, the unit will fall back but the shock infantry will follow up, which is reported as a Push Back rather than a Fall Back.
2) Cavalry will attempt to break off from cavalry if they "lose the combat round badly", but cannot break off from Shock cavalry who originally charged them.
3) Cavalry will break off from infantry, whether or not they won or lost the previous round of combat, if their chances don't look good for winning the next melee.
4) Elephants and Scythed Chariots never break off.
5) Infantry can never break off from mounted troops or elephants.