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?
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.
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.
Like so
Math.floor(Math.random()*8)*30 + 15
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With