Re: Generating random unique alphanumeric IDs - Mailing list pgsql-general

From Ivan Sergio Borgonovo
Subject Re: Generating random unique alphanumeric IDs
Date
Msg-id 20090816140214.5eb323e3@dawn.webthatworks.it
Whole thread Raw
In response to Re: Generating random unique alphanumeric IDs  (Sam Mason <sam@samason.me.uk>)
Responses Re: Generating random unique alphanumeric IDs  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-general
On Sun, 16 Aug 2009 12:48:39 +0100
Sam Mason <sam@samason.me.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


pgsql-general by date:

Previous
From: Bastiaan Wakkie
Date:
Subject: Re: A history procedure that prevents duplicate entries
Next
From: Sam Mason
Date:
Subject: Re: Generating random unique alphanumeric IDs