php random x digit number

前端 未结 21 2135
耶瑟儿~
耶瑟儿~ 2020-12-04 15:00

I need to create a random number with x amount of digits.

So lets say x is 5, I need a number to be eg. 35562 If x is 3, then it would throw back something like; 463

21条回答
  •  独厮守ぢ
    2020-12-04 15:59

    the simplest way i can think of is using rand function with str_pad

    
    

    In above example , it will generate random number in range 0 to 999.

    And having 5 digits.

提交回复
热议问题