We have a form with 2 fields and a button. We want on button click to output random int number (like 3, 5 or 33) which would lie between int A and int B? (no use of jQuery or anything like it is required)
floor(Math. random() * ((max-min)+1) + min); Generate a random integer between two numbers min and max (the min is inclusive, and the max is exclusive).
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.
var numRand = Math. floor(Math. random() * 101); That will return a random number between 1-100.
You can use Javascript Math.random
function randomInRange(start,end){
return Math.floor(Math.random() * (end - start + 1) + start);
}
Use something like Math.floor(Math.random()*(intB-intA +1)) + intA
?
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