The defense of the defender is modified by factors such as the terrain type, being behind a river, in a fortress or a town with walls, being in a city or metropolis.
If you swordsman is attacking a pike fortified on a hill ofer a river inside a city. Then he needs to fight a defense of.
Pikeman: 3 (100%)
Fortified: +25%
Hill: +50%
City: +50%
Behind river: 25%
Defense modifier: 1+0.25+0.5+0.5+0.25=2.5
Modified defense; 3*2.5=7.5
If your archer is attacking a pike that is not fortified on flat land, then he is attacking a defense of 3.3 (flat land still gives a 10% def bonus)
Also, are your swordsman and archers veteran units? (4hp) or regulars? (3hp) or maybe even elites? (5hp) and the defending pikes? If you use a regular sword to attack a veteran pike, or an veteran archer to attack a regular pike, it makes a big deference. More HP means the unit can soak up more damage before it finally dies, meaning it will have an overall higher chance of winning the whole battle.
If these defense factors for the enemy pike are the same, then there is still the random factor.
A lot of people misunderstand how randomness works.
For example, if you have a 50% chance of something being true, then a lot of people would expect a series of events like this:
1011 0101 0010 1010 1010 1010 0110
As opposed to this:
1111 1011 1011 0000 0011 1100 1010
However, if you think about it, you'll realize the first series is much more predictable than the second, and thus less random.
Ever heard of the saying "bad luck never comes alone" Well, its true! Random events happen in strokes!