There's no need for a loop. The following code does it with only one call to Math.random as the number returned always maps to within the required range with the same distribution regardless of what numbers are entered.

Code:

function generateRandomInteger(minNumber, maxNumber, minDigits, maxDigits) {
var minNum, maxNum, minDigNum, maxDigNum, range, num;
minNum = Math.min(minNumber, maxNumber);
maxNum = Math.max(minNumber, maxNumber);
minDigNum = Math.pow(10,minDigits-1);
if (minNum<0) minDigNum *= -1;
else minDigNum = Math.max(maxNum, minDigNum);
maxDigNum = Math.pow(10,maxDigits-1);
if (maxNum<0) {
maxDigNum *= -1;
if (maxDigNum<minDigNum) maxDigNum = minDigNum = maxNum;
}
else maxDigNum = Math.max(minDigNum, maxDigNum);
range =minDigNum-minNum+maxNum-maxDigNum+2;
if (minDigNum===maxDigNum) range--;
num = Math.floor(Math.random()*range)+minNum;
if (num > minDigNum) num += maxDigNum;
return num;
}