[thelist] srand in php

Jay Greenspan jay at trans-city.com
Tue Oct 23 17:04:17 CDT 2001


Interesting.

If you run this enough times you will see a 2 as the primary digit, but 
never a 3 or anything larger. That's because mt_rand returns an integer, 
and the maximum value of an integer is 2147483647.

I can think of a couple of hacky ways to get a random number that's 10 
digits, but I'd like to see what other list members will come up with.

Would a 10 character string do the trick? Or does it have to be digits? 
Do they have to be random or simply unique? Will 9 digits do work?

-j


On Tuesday, October 23, 2001, at 02:56 PM, noah wrote:

> I'm generating a random number using php - I found the information 
> about how to do it in the php manual and at phpbuilder. The random 
> number is 10 digits long, and is generated like this:
>
> mt_srand((double)microtime()*1000000);
> $key = mt_rand(1000000000,9999999999);
>
> I'm just wondering if anyone can offer any insight on why the random 
> number always begins with 1. The next nine digits appear to be random, 
> but the 40 times or so that I've run this, the first digit has always 
> been 1.





More information about the thelist mailing list