There is such a code
function randomInteger(min, max) { var rand = min - 0.5 + Math.random() * (max - min + 1) rand = Math.round(rand); return rand; } alert( randomInteger(5, 10) ); It is necessary to tune it for the output in the desired span on the class. From 1000 to 9999 (a four-digit number should be). Prompt the principle of how to implement.