Агуулга
Math.random(); // returns a random number
Math.floor(Math.random() * 10); // returns a random integer from 0 to 9
Example #
Math.floor(Math.random() * 11); // returns a random integer from 0 to 10
Example #
Math.floor(Math.random() * 100); // returns a random integer from 0 to 99
Example #
Math.floor(Math.random() * 100); // returns a random integer from 0 to 99
Example #
Math.floor(Math.random() * 101); // returns a random integer from 0 to 100
Example #
Math.floor(Math.random() * 10) + 1; // returns a random integer from 1 to 10
Example #
Math.floor(Math.random() * 100) + 1; // returns a random integer from 1 to 100
Math.floor(Math.random() * 10) + 1; // returns a random integer from 1 to 10
This JavaScript function always returns a random number between min and max (both included):
Example #
function getRndInteger(min, max) {
return Math.floor(Math.random() * (max - min + 1) ) + min;
}