First of all, determine your alphabet (the pool of characters you'll derive your 4-character code from):
- For example, using an English alphabet with both lowercase and uppercase letters and digits 0-9 makes for 62 characters (26 + 26 + 10). Then, ask if you want to allow a character to repeat itself in the 4-character code. - If so, then it's easy: take the length of your alphabet, and calculate (length)^4. In my example above, it would be 62^4 = 14,776,336 - If not, then it's a little more complicated, calculate (length) * (length-1) * (length-2) * (length-3), or in other words the factorial of length minus the factorial of (length - 4). In my example, 62! - (62-4)! = 13,388,280 AR On Tue, Jun 26, 2012 at 10:52 AM, Sithembewena Lloyd Dube <zebr...@gmail.com > wrote: > HI, > > Would anyone have tips on how to generate random 4-digit alphanumeric > codes in python? Also, how does one calculate the number of possible > combinations? > > Thanks in advance. > > -- > Regards, > Sithembewena Lloyd Dube > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor