Re: Generating random unique alphanumeric IDs

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Cc: <thombrown(at)gmail(dot)com>
Subject: Re: Generating random unique alphanumeric IDs
Date: 2009-08-16 12:02:14
Message-ID: 20090816140214.5eb323e3@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 16 Aug 2009 12:48:39 +0100
Sam Mason <sam(at)samason(dot)me(dot)uk> wrote:

> On Sun, Aug 16, 2009 at 12:07:27PM +0100, Thom Brown wrote:
> > Does anyone know a way to generate a random and unique lowercase
> > alphanumeric ID
>
> If you want it to be unique then it's not going to be random. The
> easiest way to keep it from producing duplicates is to have some
> monotonically increasing component. If you're OK with code/people
> retrying the occasional duplicate then you're going to be relying
> on statistical guarantees and you should look at "birthday
> attacks" to see how often this is going to happen.
>
> > Notice that I don't mean hexadecimal values either. This would
> > preferrably not resort to trying to generate the ID, then
> > checking for a clash, and if there is one, do it again, although
> > that could do as I can't think of how the ideal solution of a ID
> > hashing algorithm would be possible.

Sometimes ago Daniel Verite posted an implementation of a fiestel
cipher in plpgsql.

I'm happily using it to generate pseudo-random hex strings.

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sam Mason 2009-08-16 12:25:26 Re: Generating random unique alphanumeric IDs
Previous Message Bastiaan Wakkie 2009-08-16 12:01:25 Re: A history procedure that prevents duplicate entries