php random x digit number

前端 未结 21 2150
耶瑟儿~
耶瑟儿~ 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条回答
  •  Happy的楠姐
    2020-12-04 15:36

    you people really likes to complicate things :)

    the real problem is that the OP wants to, probably, add that to the end of some really big number. if not, there is no need I can think of for that to be required. as left zeros in any number is just, well, left zeroes.

    so, just append the larger portion of that number as a math sum, not string.

    e.g.

    $x = "102384129" . complex_3_digit_random_string();

    simply becomes

    $x = 102384129000 + rand(0, 999);

    done.

提交回复
热议问题