When setting up a npc, class, or weapons you select the damage formula to use (physical, magical or true). You also select the scaling stat for the damage to be based off of.
The scaling stat value is pulled from the character/npcs stats whether its attack, speed, ability power or anything else -- so these values are important.
The defensive stat is either defense or magic resist and this solely depends on whether you choose the attack to be physical or magical.
True damage does not take defensive stats into account whatsoever.
In the formula itself the Random(,) function works in such a way that if you give it 2 values it will return something within those values. Ie: Random (0,5) might return 0, 1, 2, 3, 4, or 5. So the comma you see in the formulas isn't for defense but rather separating the lowest and highest damage calculations that could happen and picking something in the middle.