Re: Unique random string

From: Date: Wed, 28 Jun 2000 03:06:26 +0000
Subject: Re: Unique random string
Groups: php.general 
Request: Send a blank email to php-general+get-3495@lists.php.net to get a copy of this message
I don't remember the function's names off of the top of my head, but you could create a hash off of the current timestamp / random number. I think *something* like this would work: $str = substr(md5(time()),0,15); It's probably as unique as unique can get under your circumstances. You could also use a random number instead of time(), if you are generating strings at the same exact millisecond. -- Matthew Leverton - matthew@aeroinc.net http://www.allegro.cc -----Original Message----- From: William Ahern <wahern@mailshell.com> To: php-general@lists.php.net <php-general@lists.php.net> Date: Tuesday, June 27, 2000 6:47 PM Subject: [PHP] Unique random string >Any ideas on how I can generate a 'guaranteed' unique ascii string less than >15 characters. > >It must be guaranteed unique across several independent >servers. > >Currently we are generating random short strings to create unique aliases for >email addresses. The only problem is that to guarantee uniqueness we keep a log >of previous strings and check to make sure we don't create duplicates (we cannot >rotate strings. They must be absolutely unqiue for the next decade or so). > >The optimal solution would be to generate strings that are truly unique and >hopefully random enough, w/o having to go through the process of checking for >duplicates. > >I'd use uniqid(), except that it is 32 characters (too long since users will >have to handle them sometimes) and the algorithm must be available to C, C++, >Perl, whatever. > >Any comments, suggestions or answers! ;) would be great. > >Please add my address to the reply as I am not subscribed to the list. > >TIA, > >Bill > >-- >PHP General Mailing List (http://www.php.net/) >To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net >For additional commands, e-mail: php-general-help@lists.php.net >To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#3495) next »