0

In PHP, I need to find a way to generate random integers between 1 and 46938003261

The rand function seems to be unable to generate numbers larger than 9 digits long, which is a problem for me given my 11 digit long max number.

rand (1 , 46938003261)

I realize this is a limitation of PHP on 32 bit systems, and I can verify that I have had the same issue using mt-rand instead of rand.

How can I generate a random integer between 0 and 46938003261 with PHP?

Thanks!

  • I think this is a good solution: http://stackoverflow.com/a/1504655/1696795 – Mario A Jan 19 '15 at 07:48
  • Possible duplicate of [In PHP, how do I generate a big pseudo-random number?](http://stackoverflow.com/questions/1479823/in-php-how-do-i-generate-a-big-pseudo-random-number) – LF00 Jul 24 '16 at 02:35

1 Answers1

0

Append 2 numbers and concatenate them

rand (0 , 46938003261) + rand (10 ,100 ) 

But make sure you convert them to string and then add (?)

Another approach is to check the size of string before concatenating them.

Paul L.
  • 50
  • 1
  • 9
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78