Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript Random Number Between 15 and 225 Increments of 30?

Hi I need to generate a random number in JavaScript between 15 and 225 that can only be by increments of 30. For example: 45, 75, 105 etc.

Any ideas on how this can be done? I'm aware of Math.floor(Math.random()*11) for example for a random number 1-10 but how can this be modified to fit in with what I'm trying to do?

like image 563
Dan Avatar asked Jan 18 '12 03:01

Dan


People also ask

How do you generate a random number between two values in JavaScript?

Example: Integer Value Between Two Numbers In JavaScript, you can generate a random number with the Math. random() function. The above program will show an integer output between min (inclusive) to max (inclusive). First, the minimum and maximum values are taken as input from the user.

How do you assign a random number in JavaScript?

Generating Javascript Random Numbers Javascript creates pseudo-random numbers with the function Math. random() . This function takes no parameters and creates a random decimal number between 0 and 1. The returned value may be 0, but it will never be 1.


1 Answers

Like so

Math.floor(Math.random()*8)*30 + 15
like image 81
Joe Avatar answered Oct 02 '22 16:10

Joe