RE: [PHP] Unique random string
| From: | Henrik Johansson | Date: | Wed, 28 Jun 2000 11:51:51 +0000 |
| Subject: | RE: [PHP] Unique random string | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-3539@lists.php.net to get a copy of this message | ||
That´s a good approach!
Using the time()-function in php would implement this nicely as it
returns the number of seconds since the 1st January 1970.
To avoid more than one user to register email-alias during the
one-second interval it takes time() to increment, a table-lock could be
issued and released after it´s been verified that the time() has in fact
incremented one second.
Happy Hacking,
Henrik J.
> ----------
> From: Dan[SMTP:dan@savage-comedy.com]
> Sent: den 28 juni 2000 13:26
> To: php-general@lists.php.net
> Subject: FW: [PHP] Unique random string
>
> Why not just have an integer that gets incremented. Represent it as a 14
> digit hex number. Use the 15th digit as a prefix for the year..
> 1AAAAAAAAAAA
> is year one, 2AAAAAAAA is the second year, and so on.
>
> If you need to check them against previous strings, build a table for that
> year of only the IDs you've generated with '1', the next year '2',
> etc. It
> should be a small subset of all of your random IDs.
>
> Dan Sevush
> CTO Dan's Chocolates
> Happy PHP site since 11/99
> www.danschocolates.com
>
>
> > -----Original Message-----
> > From: William Ahern [mailto:wahern@mailshell.com]
> > Sent: Tuesday, June 27, 2000 7:35 PM
> > To: php-general@lists.php.net
> > 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
> >
>
>
> --
> 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
>