:::: MENU ::::

Generating lottery codes – how many combinations will I have?

Here is a task. You have to prepare the schema for lottery codes. You have to generate lets say 1 000 000 codes that are 6 characters long. Client’s question is ‘Is that safe?’. This is a good question and you have to do some basic math to be sure that the combination of the code length and alphabet size give you enough combinations so users can’t guess other codes.

Simple example

Alphabet: A, B
Code length: 3 characters

So we have possible combinations:

AAA
AAB
ABA
ABB
BBB
BBA
BAA
BAB

So we have 8 possible combination for 3 characters code with 2 characters alphabet.

23 = 8

Later on, if we have 11 characters in our alphabet and 9 character code we will have

119 = 2 357 947 691

so if client wants 1 000 000 of codes, this scheme seems to be quite secure since is like 0,0424% of all possible combinations.