Making Random Number

I am trying to make a random number between 1 and 1,000. I have a code that seems to work correctly, but I don’t completely understand it and after looking online I think it might be wrong.


var rnd = Math.floor(Math.random()*999)

Thanks.

Wow, I really don’t like Javascript too much. Its so much different then other languages.

Thanks for the reply.

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;