Simplest way in my opinion is:
- find a desired number in range
[1,10000000)
, let it bex
and it will represent your 6 digits. - Find 3 characters (let's assume in range a-z). Let them be
a,b,c
. - Your number is
(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).