Re: [PHP] Random Unique ID

2007-03-24 Thread Jim McIntyre
IIRC, the OP wanted to generate a unique key precisely to keep from revealing the record ID to the end user... what about taking the auto_increment value (easy to generate, assured to be unique) adding its MD5 hash to another column in the table, then using that as the published ID? The only

Re: [PHP] Random Unique ID

2007-03-24 Thread Robert Cummings
On Sat, 2007-03-24 at 08:24 -0400, Jim McIntyre wrote: IIRC, the OP wanted to generate a unique key precisely to keep from revealing the record ID to the end user... what about taking the auto_increment value (easy to generate, assured to be unique) adding its MD5 hash to another column in the

Re: [PHP] Random Unique ID

2007-03-23 Thread Németh Zoltán
2007. 03. 22, csütörtök keltezéssel 12.58-kor tedd ezt írta: At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: As for efficiency, that's probably not even worth mentioning in this case. why not? you would use 2 sql queries

Re: [PHP] Random Unique ID

2007-03-23 Thread Robert Cummings
On Fri, 2007-03-23 at 09:15 +0100, Németh Zoltán wrote: // method 2 $time = microtime(TRUE); for ($i = 1; $i = 5000; $i++) { $done = FALSE; while (!$done) { $id = md5((microtime(TRUE) * (rand(1,1000) / 100))); $sql = INSERT INTO idtest (id,cnt)

Re: [PHP] Random Unique ID

2007-03-23 Thread Németh Zoltán
2007. 03. 23, péntek keltezéssel 08.13-kor Robert Cummings ezt írta: On Fri, 2007-03-23 at 09:15 +0100, Németh Zoltán wrote: // method 2 $time = microtime(TRUE); for ($i = 1; $i = 5000; $i++) { $done = FALSE; while (!$done) { $id = md5((microtime(TRUE) *

Re: [PHP] Random Unique ID

2007-03-23 Thread tedd
At 9:15 AM +0100 3/23/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 12.58-kor tedd ezt írta: At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: As for efficiency, that's probably not even worth mentioning in this

Re: [PHP] Random Unique ID

2007-03-23 Thread Németh Zoltán
2007. 03. 23, péntek keltezéssel 15.13-kor tedd ezt írta: At 9:15 AM +0100 3/23/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 12.58-kor tedd ezt írta: At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: As for

Re: [PHP] Random Unique ID

2007-03-23 Thread Richard Lynch
Use auto_increment. It's not random, but you should never show it to the end user anyway, so who cares? Another option is to use http://php.net/uniqid and you can create a UNIQUE INDEX on the column and simply check mysql_errno() to see if it's 1023 (or is it 2023?) when you insert to see if you

Re: [PHP] Random Unique ID

2007-03-22 Thread tedd
At 11:18 AM -0600 3/21/07, [EMAIL PROTECTED] wrote: Hello, I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as

Re: [PHP] Random Unique ID

2007-03-22 Thread Németh Zoltán
2007. 03. 22, csütörtök keltezéssel 11.24-kor tedd ezt írta: At 11:18 AM -0600 3/21/07, [EMAIL PROTECTED] wrote: Hello, I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no

Re: [PHP] Random Unique ID

2007-03-22 Thread tedd
At 4:28 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.24-kor tedd ezt írta: At 11:18 AM -0600 3/21/07, [EMAIL PROTECTED] wrote: Hello, I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like

Re: [PHP] Random Unique ID

2007-03-22 Thread Németh Zoltán
2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: At 4:28 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.24-kor tedd ezt írta: At 11:18 AM -0600 3/21/07, [EMAIL PROTECTED] wrote: Hello, I want to add a random unique ID to a Mysql table.

Re: [PHP] Random Unique ID

2007-03-22 Thread tedd
At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: As for efficiency, that's probably not even worth mentioning in this case. why not? you would use 2 sql queries while I would use one most of the time and 2 in case of already reserved

Re: [PHP] Random Unique ID

2007-03-22 Thread Németh Zoltán
2007. 03. 22, csütörtök keltezéssel 12.58-kor tedd ezt írta: At 4:53 PM +0100 3/22/07, Németh Zoltán wrote: 2007. 03. 22, csütörtök keltezéssel 11.42-kor tedd ezt írta: As for efficiency, that's probably not even worth mentioning in this case. why not? you would use 2 sql queries

[PHP] Random Unique ID

2007-03-21 Thread ccspencer
Hello, I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as to the right way to go about doing this? Best,

Re: [PHP] Random Unique ID

2007-03-21 Thread Stut
[EMAIL PROTECTED] wrote: I want to add a random unique ID to a Mysql table. Collisions are unlikely but possible so to handle those cases I'd like to regenerate the random ID until there is no collision and only then add my row. Any suggestions for a newbie as to the right way to go about

Re: [PHP] Random Unique ID

2007-03-21 Thread Rabih Tayyem
function GenerateID () { $len = 3; $base='ABCDEFGHKLMNOPQRSTWXYZ'; $max=strlen($base)-1; $activatecode=''; mt_srand((double)microtime()*100); while (strlen($activatecode)$len+1)$activatecode.=$base{mt_rand(0,$max)}; $len = 7; $base='1234567890'; $max=strlen($base)-1;