Sweep and reward support Q Group communication651176910Shared thePeople support!!!
With JavaScript's math.random () method, you can get random numbers from 0 to 1, so how do you get the number randomly between any given two numbers? such as obtaining a random number between 2 and 5, a random number between 5 and 10, etc.
Since the math.random () function always returns a random number from 0 to 1, we can think of 0 as the minimum number and 1 as the maximum number. Assuming that the minimum number is Max and the maximum number is min, we can draw a random number between any two numbers using the following formula:
Math.random () * (max-min) + min
If you use Math.floor () for a down-rounding operation, you need to Max-min + 1, which is:
Math.floor (Math.random () * (max-min) + min)
If you want to specify the number of decimal digits, you can use the math.round () function. As the following formula returns a random number between any two integers, the result retains 1 decimal places:
Math.Round ((Math.random () * (max-min) + min) * 10)/10
JavaScript gets any random number between two numbers