Re: generating unique id's

From: Date: Wed, 30 Jun 1999 02:14:09 +0000
Subject: Re: generating unique id's
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-769@lists.php.net to get a copy of this message
Hi: I use the following code: <? for ($i = 0; $i < 5; $i++) { mt_srand((double)microtime()*1000000); $randval[$i] = mt_rand(); } for ($i = 0; $i < 5; $i++) { echo $randval[$i],"<BR>"; } ?> or <? // Method 2 mt_srand((double)microtime()*1000000); ECHO "<FONT COLOR=RED>"; for ($i = 0; $i < 5; $i++) { $randval[$i] = mt_rand(); } for ($i = 0; $i < 5; $i++) { echo $randval[$i],"<BR>"; } ECHO "</FONT>"; ?> and the result is: 122653537 849966493 749620674 706811529 86123690 2074739843 1867927643 1706046782 1795463355 1221802180 Any one can meet your needs, you see. If you can't, maybe your computer is too good. :-) ------------------------------------- # Edward Wong # # # # E-Mail:wyuanzheng@21cn.com # # Phone: 86-21-63615261 * 207 # # # # iSpaceBank Group, Shanghai, China # # # ------------------------------------- ----- Original Message ----- From: "Cody Caughlan" <codyc@cisco.com> To: <php-db@lists.php.net> Sent: Thursday, June 29, 2000 6:10 AM Subject: [PHP-DB] generating unique id's > Hello, > > I need to generate a unique id. The problem I am running into is this: > I have a for loop that generates a bunch of id's using the time() > function, the problem is that since the for loop only takes less than a > microsecond, and the precision of the time() function is a microsecond, > all the id's are the same. I looked into using uniqid(), which according > to the PHP manual generates an INT. However, I tested it out, and in a > microsecond it DOES generate a series of different, random STRINGS, mix of > ints and characters, NOT an INT, which like I said is what the PHP manual > uses. MySQL requires that the primary key be an INT, so I can use uniqid() > function to generate this id, because its a string. > > What can I do? > > In summary, generate a whole list of unique INTEGER id's in under a > microsecond... > > Thanks > /Cody Caughlan > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.db (#769) next »