cambia riga medesima con questa:
var nrandom = Math.floor(Math.random() * (999999)).toString().substring(0,4)