Answer the question
In order to leave comments, you need to log in
How to organize the generation of unique codes?
The problem is not only that it is impossible to generate unique codes, the problem is in additional generation. For example, you need to generate 500k codes, let's say there are already 400k in the database, the question is how to generate the required number of codes in less time. In order not to do 400k checks, to add 400,001 codes.
I apologize for not being complete. Codes can be of different lengths. The service also sets some rules for codes, for example, the length of the code and the alphabet.
Answer the question
In order to leave comments, you need to log in
Use the formula: CODE=N.
Where code is the code and N is the serial number.
Or a more complex formula for code dependence on N without collisions.
Another option: to make a single 3-dimensional matrix for all existing codes for each character: character, position, code id.
Where empty cells remain, these are free combinations (acquaintance) for new codes.
You can try using a GUID. They are said to be unique. Those. you can not check for the presence of the same in the database when inserting a new one.
Well, or a unique code can be an integer. We find the maximum which is already stored in the database and start generating upwards from it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question