[Tutor] Generating random alphanumeric codes

taserian taserian at gmail.com
Tue Jun 26 17:09:58 CEST 2012


Correcting what was said below.

- 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 divided by the factorial of (length - 4). In my example, 62! /
(62-4)! = 13,388,280

On Tue, Jun 26, 2012 at 11:08 AM, taserian <taserian at gmail.com> wrote:

> 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 <
> zebra05 at 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 at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120626/20358528/attachment-0001.html>


More information about the Tutor mailing list