Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
54
rated 0 times [  58] [ 4]  / answers: 1 / hits: 30832  / 11 Years ago, fri, september 20, 2013, 12:00:00

I know there's several questions on this, but I'm struggling to find out how to use Math.random to get random numbers between two high integers?



So, for example, between 50 and 80. I thought this would work...



'left': Math.floor((Math.random() * 80) + 50) + '%'


Any ideas?


More From » javascript

 Answers
1

You need to know the range of the random.



Between 50 and 80, the range is 30 (80 - 50 = 30), then you add 1.



Therefor, the random would look like this :



Math.floor(Math.random() * 31) + 50

[#75560] Thursday, September 19, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tatianah

Total Points: 185
Total Questions: 99
Total Answers: 87

Location: Sao Tome and Principe
Member since Wed, Dec 21, 2022
1 Year ago
;