Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Need pointer for algorithm on generating alphanumeric sequence. The requirement is as follows.

Only 0-9, A-Z and a-z characters can be used. Initially the sequence will start with only one character and when the sequence has been exhausted will it go to two characters and similarly the sequence will be incremented when the previous sequence has been exhausted.

Example of the sequences are given below

One Character sequence

0 1 2 .. 9 A B .. Z a b .. z

Now the one character sequence has been exhausted. Then a 2 digit series will start.

00 01 02 .. 09 0A 0B .. 0Z 0a 0b .. 0z 10 11 .. 19 1A .. 1Z 1a 1b .. zz

After two characters series has been exhausted then 3 character series will start as given below

000 ... zzz

And the series will generate till the 12 character series has been exhausted.

Can anybody help me point to some link or suggest me the mechanism to do it?

I am trying to do this in PHP.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
188 views
Welcome To Ask or Share your Answers For Others

1 Answer

Python:

digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

def NthStr(n):
    str=digits[n%len(digits)];
    while n>=len(digits):
        n=(n/len(digits) - 1)
        str=digits[n%len(digits)]+str
    return str

Try it (with fewer digits, so you can see the pattern): https://ideone.com/rZEV1m

I imagine this would be pretty easy to translate into PHP


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...