Math.random(); Help


#1

If I were to make a Math.random(); or Math.floor(Math.random()); and use console it would make a number like 6 or something. What if I want the number to only be chosen from 1-3 and it would choose 1 2 or 3 randomly. How would I make this code?

Sorry if I didn’t choose the right getting started category! I’m new to the whole forums thing.


#2

see here:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random#Getting_a_random_number_between_two_values

The math is explained. If the random value can be zero, -min and +min can be excluded


#3

Thanks for the help! : )


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.