Re: Generating random unique alphanumeric IDs

Поиск
Список
Период
Сортировка
От Thom Brown
Тема Re: Generating random unique alphanumeric IDs
Дата
Msg-id bddc86150908200534p14723ac2vd1ef223af095d822@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Generating random unique alphanumeric IDs  (Ivan Sergio Borgonovo <mail@webthatworks.it>)
Ответы Re: Generating random unique alphanumeric IDs
Re: Generating random unique alphanumeric IDs
Список pgsql-general

Since I'm then converting to_hex to shorten the string I was
thinking to add some more bits of randomness since eg.

to_hex(10) =  'a'

In the line of
select lpad(
 to_hex(feistel_encrypt(10)),7 , to_hex((rand()*2^31)::int)
);

I was wondering if there is any better way to get alphanumeric
random string quickly. Since uniqueness is assured by passing a
sequence to fesitel_encrypt, I just need turning into to
alphanumeric quickly.


This appears a lot more tricky than I had originally anticipated!  I may be misunderstanding your example, but by alphanumeric, I mean beyond hex (i.e. a-z and possibly uppcase too).

I've looked into LFSR, but I'm afraid it goes over my head.   But what Jason Betts said seems to summarise what I'm after: "for the OP's problem this means building a LFSR with n=5c (where c is the number of charactes in the serial code, and n is the number of bits in the LFSR state) and then taking a single LFSR result and peeling off 5 bits at a time and using each 5 to make each charcter in the result."

If this results in an unpredictable and non-duplicating loop of generated sets of characters, that would be ideal.  Would a parallel for this be a 5-character code possibly transcoded from a 6-character GUID/UUID? (a-h + j+n + p-z + A-H + J-N + P+Z + 2-9 = 56 possible characters, 56^5 = 550,731,776,   550,731,776 / 16 (hex character set) ^ 6 (characters) = just over 32.), so wouldn't actually use up all possible combinations. :/

Thom

В списке pgsql-general по дате отправления:

Предыдущее
От: Karsten Hilbert
Дата:
Сообщение: Re: Unit conversion database (was: multiple paramters in aggregate function)
Следующее
От: Karsten Hilbert
Дата:
Сообщение: Re: multiple paramters in aggregate function