+ 2
How can i get a random number between two numbers?
3 Answers
+ 4
also, wrap everything in Math.floor for it to be an integer number only as Math.random() returns a number in the range [0, 1)
+ 2
Math.random() * (max - min) + min;
+ 1
i can give the java code .
let us take the two numbers as 5 and 10
let us store it in n
then the syntax will be
int n=(int)((Math.random()*(10-5))+5);
now explanation
(int) for getting an int number
(10-5) to get the number of random numbers to be generated
so the number generated can be 0 also so we add the lower limit 5 .so that the lowest number generated is the lower limit only.
be aware the largest number generated in this case is 9 .you will have to adjust the code accordingly.