Army left in Territory.

In this case the mode is Attrition. How remaining army is calculated?
Whats the formula, because Is it the bug because sometimes it fails so much, unless some new Engines are made to work as 3rd party..
And if you do not know or Lopdo does not want to publish it what are the %. How can Territory with 8 attack territory 7 (Dice 30 vs 20) and have only 7 left or territory 4 attacking 3 (dice 15 vs 10) and have 3 left. The defender rolls more than HALF (50% I mean) and in this case defender is with lower dice and attacker wins but they still lose only 1 army. How is this possible..? Am I missing something here?
Those numbers are not taken out of random thin air. Just finished another game and lately I see a lot of such things. I never see an attacker to lose a LOT so in this case It cant be LUCK or random that determines the army left?
ATTRITION (Att) - similar to hardcore, but attacker can lose some dice even if he wins. Same applies to defender, even if attack fails, it can weaken defender. Exact amount of lost dice is determined by dice throws. In short, better your throws, less dice you lose.
Whats the formula, because Is it the bug because sometimes it fails so much, unless some new Engines are made to work as 3rd party..
And if you do not know or Lopdo does not want to publish it what are the %. How can Territory with 8 attack territory 7 (Dice 30 vs 20) and have only 7 left or territory 4 attacking 3 (dice 15 vs 10) and have 3 left. The defender rolls more than HALF (50% I mean) and in this case defender is with lower dice and attacker wins but they still lose only 1 army. How is this possible..? Am I missing something here?
Those numbers are not taken out of random thin air. Just finished another game and lately I see a lot of such things. I never see an attacker to lose a LOT so in this case It cant be LUCK or random that determines the army left?