Double-posting to give YET another update on the damage formula in DP.
The Critical Hit (x2) multiplier is done before the random number generation multiplier.
So the damage formula now becomes:
(((((2 + (Level × 2 ÷ 5)) × BasePower × [Sp]Atk) ÷ [Sp]Def) ÷ 50) + 2) × CH × R × STAB × Type1Effectiveness × Type2Effectiveness
where CH is 2 if the move is a critical hit, 1 otherwise.
Also, I don't yet have any proof whether R is a random integer between 85 and 100 and then divided by 100, or if R is a random integer between 217 and 255 and then divided by 255. So I will just write it as R for the time being, until I get proof about the former or the latter.
However, I will try to crack that mystery soon. Stay tuned.