-1

I am trying to generate a random number with a minimum and maximum value. Currently I have the following variable that generates numbers between 0-2000. I want to be able to generate a between 500 and 2000. Will need to create local variables to achieve this?

random = Math.floor(Math.random()*2000);
ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
David
  • 31
  • 1
  • 6

1 Answers1

1
Math.random() * (max - min) + min);

If you need to generate more than one random number you need more than one variable.

Edit: One parentheses was missing in the code example

pvxe
  • 90
  • 2
  • 9
Alvaro Royo
  • 156
  • 8