Not random!!!
Miscalculated, maybe, but surely not random !!
Actually, I have seen mages use low-range or "touch"-spells quite often when faced with attacking troops - or assassines.
Had a quite funny assassination in Dom2: Beeing stabbed with a poison dagger, my weaponless Pan retaliated in kind and used poison touch. Then both missed each other for 3 combat turns - until the assassin dropped dead from the poison, while the Pan escaped unharmed.