I am developing a application where user is only authenticated if he enters a serial key correctly. This serial key is matched with the serial key already present in database. This serial key should consists of 6 digit and 3 alphabets. Users get these key in written form from me.
How do I generate a large number (100,000,000 approx) of serial keys?
Simplest way in my opinion is:
[1,10000000)
, let it be x
and it
will represent your 6 digits.a,b,c
.(a-'a' + b-'a'*26 + c-'a'*26*26)*10000000 + x
(Where 'a' is the ascii representation of the character 'a'
, and a-'a' means the numeric ascii subtraction)
Note that the generated number can even fit in a long
- assuming it is 64 bits.
Generation of several numbers can be simply done with iteration, start with a=b=c='a'
, and x=0
, and start advancing (increase by 1). Once you reached x=10000000
, increase a, if a
passed z - increase b
, .... (similar to what you would do in normal integer addition arithmetic).