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.tsx177 chars5 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