jeudi 15 juin 2017

Python - Create million of unique alphanumeric codes with high performance

actually I am stuck with the following business case and do not have an idea how to solve it.

I have to create more than 5.000.000 unique alphanumeric codes.

The rules for the codes are:

length: 12
format: every 4 digits "-"
some letters should be excluded like: O or l

The codes should be "secure" (i.e totally random) and it should be possible to run the script multiple times in case the codes aren't enough and we have to create more codes.

e.g. ab4D-406a-BCh7-TEs3

I have to solve this in Python 3.

My first idea was to save the codes into an database and just create them with the random function ASCII-Code -> Letter but maybe the scirpt creates the same code twice so I habe to check every time if that code already exists in the database which will cause a lot of database traffic.

My second idea is to use a hash function, but I think the codes wouldn't be secure and there are no hashfunctions which pass my rules.

My third idea is to use somethink like a random module from python to create the code and write the codes into an file and check the file every time if the code is already inside. But that's also not good for performance but I think betther than using a database.

Anybody an idea how to solve that problem with high performance?

Greetings.




Aucun commentaire:

Enregistrer un commentaire