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

前端 未结 22 2356
攒了一身酷
攒了一身酷 2021-01-30 10:23

I\'m trying to generate a random number that must have a fixed length of exactly 6 digits.

I don\'t know if JavaScript has given below would ever create a number less th

22条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-30 10:31

    100000 + Math.floor(Math.random() * 900000);
    

    will give a number from 100000 to 999999 (inclusive).

提交回复
热议问题