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

前端 未结 22 2390
攒了一身酷
攒了一身酷 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:34

    I use randojs to make the randomness simpler and more readable. you can pick a random int between 100000 and 999999 like this with randojs:

    console.log(rando(100000, 999999));

提交回复
热议问题