Generate a 5-digit 14-character unique identifier

I have a unique input string of 14 characters, for example BR004395285678

, and I want to map it to multiple unique characters ids

. Is there a way to do this other than using auto-incrementing IDs?

+3


source to share


2 answers


1) In general, you cannot 100% guarantee that 5 char strings will be unique.
This is because a 14 character string can be larger than all possible 5 char.
This assumes the alphabets of strings 5-char and 14-char are the same.

2) In practice, if some of the characters in the 14 char strings are meaningless (i.e. always the same for the entire set of 14 char strings), then you can use a simple collation, for example, for example.

BR00 43952 85678 → 85678

to create a set of five char strings.



For this simple display idea, use this part of your 14-char strings which is the most volatile, most volatile compared to the 14-char set of bites (this will usually be the last 5 digits part).

3) The best solution is to use a different alphabet for your 5 char strings.

eg. add a leading 0 to BR00 43952 85678. You get 0BR 004 395 285 678.
Break this down into groups of 3 characters as shown above.
Now encode each triplet bijection into char / from another
(larger) alphabet. It is guaranteed that you get 5 char and unique.

+1


source


You have 26 ^ 2 * 10 ^ 12 unique possibilities, and you need that at least 6.8 * 10 ^ 14 characters to represent 50 bits of information to it. those. 7 bytes. You can use 4 characters if you assume that each character is 16-bit (excluding invalid ones), but is that what you mean?



As peter.petrov shows, if you split the string into DDD DDD DDD DDD DDD DDD and you can encode 1000 characters per character using 16-bit characters, you should use 5 characters instead of 4 as above.

0


source







All Articles