It's not all that random.
Here's the formula:
Attacker generally will get a 3 to 1 advantage (this simulates air and space superiority).
Add to that various improvement modifiers and then a technology modifier (the more tech you have, the better you do).
Attacker rolls between a 1 and a 16
Defender rolls between a 1 and a 4
We then take the square root of that result to use as our base:
exmaple:
I.e. Attacker rolls an 8 and defender rolls a 2.
Square root of 8 = 2.8
Square root of 2 = 1.4
Multiply by the various improvements (plantary defense adds 25% bonuse to your planet for instance):
Now it's 2.8 v 1.75
Now multiply by the technology:
Let's say defender has researched 10,000 worth of technology (10,000 resources of tech)
And attacker has done 5,000 worth of tech.
Defender gets 2 and attacker gets 1.
So now it's:
3.8 v 3.75
and off it goes.
Now obviously there is a luck factor.
Worst case attacker rolls a 16, defender rolls a 1.
So the base would have been 4 to 1.
End result would have been changed to:
5 vs. 3.
Not quite as massive of a difference as one might think.
But LUCK does matter. The US won the battle of Midway due to luck. BTW, the current invasion system doesn't follow the formula I've outlined here, it's being modified as we speak.