Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
30
rated 0 times [  33] [ 3]  / answers: 1 / hits: 37230  / 13 Years ago, sun, february 26, 2012, 12:00:00

Possible Duplicate:

Generating random numbers in Javascript






I have the following code var randomnumber=Math.floor(Math.random()*101); that generates a random number for me between 1 and 100. What I would like to do is generate a random number between -100 and 100. I am not sure what to do exactly. Any help would be appreciated.


More From » random

 Answers
26

First, generate a random number between 1 - 200 then subtract 100:



var randomNumber = Math.floor(Math.random() * 201) - 100;

[#87205] Friday, February 24, 2012, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kaitlynd

Total Points: 470
Total Questions: 108
Total Answers: 120

Location: Faroe Islands
Member since Thu, Apr 8, 2021
3 Years ago
;