A Random Number Generator (RNG) is a system that produces numbers in an unpredictable way. It is widely used in gaming, cryptography, simulations, and statistical sampling.
JavaScript provides a built-in function Math.random()
that generates a random decimal number between 0 and 1. To get a number in a specific range, we can use:
function getRandomNumber(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
Enter a minimum and maximum value below, then click “Generate” to get a random number.