Re: Generating random unique alphanumeric IDs
От | Ivan Sergio Borgonovo |
---|---|
Тема | Re: Generating random unique alphanumeric IDs |
Дата | |
Msg-id | 20090816140214.5eb323e3@dawn.webthatworks.it обсуждение исходный текст |
Ответ на | Re: Generating random unique alphanumeric IDs (Sam Mason <sam@samason.me.uk>) |
Ответы |
Re: Generating random unique alphanumeric IDs
|
Список | 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 по дате отправления: