generate a random number between 11111 and 99999 in javascript

You can use the Math.random() method to generate a random number between 0 and 1, and then multiply it by the range you want and add the starting number of your range. Here's how you can generate a random number between 11111 and 99999 in JavaScript:

index.tsx
const min = 11111
const max = 99999
const randomNum = Math.floor(Math.random() * (max - min + 1) + min)
console.log(randomNum) // prints a random number between 11111 and 99999
177 chars
5 lines

The Math.floor() method is used to round down the result of the multiplication to the nearest integer value. In this case, it ensures that the generated number is within the given range of 11111 to 99999 (inclusive).

gistlibby LogSnag