zeyang song
zeyang song

Reputation: 79

Four strings generate unique ids

A fixed string of 21 plus 4 strings (use the numbers 0-9 and the letters a-z,), a total of 25, how to generate more than 400,000 or more unique ids with only the last four digits modified!

example:

this is fixed encoding:111122111111112111111

This is their unique identification:  11ab

Final result : 111122B11161112111119 11ab

Can also be like this  111122B11161112111119 1234

As long as the last four strings are unique

Upvotes: 0

Views: 59

Answers (1)

Osman Mamun
Osman Mamun

Reputation: 2882

You can use itertools.permutations:

from itertools import permutations  
from random import shuffle
l = [str(i) for i in range(1, 11)] + [i for i in 'abcdefghijklmnopqrstuvwxyz']
out = [i for i in permutations(l, 4)]
shuffle(out)
out = out[:400000]

Here, you will have 400000 unique tuples. Then you can join them with the fixed string to produce desired ID's.

To produce the ID:

id = '111122111111112111111' + ''.join(out[0])

Upvotes: 1

Related Questions