How to Generate a random number of fixed length using JavaScript?

The Solution to How to Generate a random number of fixed length using JavaScript? is


_x000D_
_x000D_
console.log(Math.floor(100000 + Math.random() * 900000));
_x000D_
_x000D_
_x000D_

Will always create a number of 6 digits and it ensures the first digit will never be 0. The code in your question will create a number of less than 6 digits.

~ Answered on 2014-02-16 21:07:57


Most Viewed Questions: