benjaminhull benjaminhull - 3 months ago 7
MySQL Question

What is a good character length for a code when we need 1 million unique variations?

I need a good trade off between readability (e.g. not too long) vs being long enough to create 1 million unique variations.

The code can use numbers and letters.

We need to provision 1 million unique voucher codes and I am designing the model.

It is probably inconsequential, but we will be using MySQL to stored the codes.

Answer

If You use 26 Letters (latin alphabet eg. UPPERCASE only) + 10 digits (0,1,...,9) gives you 36 different choices of alphanumeric characters. Combination of 4 alphanumeric characters:

36 * 36 * 36 * 36 = 1679616

gives us 1679616 different combinations.

If You would add two extra characters it gives us:

36 * 36 * 36 * 36 * 36 * 36 = 2176782336

2176782336 possible voucher codes. Pick randomly one million from over 2 billions and store them in a table.