In Javascript, how do I create a random even number multiplied by 20 between 0 – 580?
E.g.: 220, 360, 180, 0 (min), 400, 200, 580 (max)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You want increments of 20, so what you really need is an integer in the range 0 to 29, and then multiply with 20. Example:
We are adding one to
max, because Math.random() is a uniformly distributed number between (inclusive 0) and (exclusive 1), so since we use Math.floor, the maximum must be 1 larger.