That is giving random numbers between 0 and 998 not between 1 and 1000.
Math.random() returns a random number that is greater than or equal to zero and less than one.
If you multiply that by 1000 you get a random number greater than or equal to zero and less than 1000.
Math.floor will remove the decimal portion leaving you with an integer between zero and 999.
Add one to it to get a number between 1 and 1000.
var rnd = Math.floor(Math.random()*1000)+1;