Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

php - Auto incrementing alphanumeric sequence

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...