[Tutor] Generating random alphanumeric codes

Hugo Arts hugo.yoshi at gmail.com
Tue Jun 26 17:04:40 CEST 2012


On Tue, Jun 26, 2012 at 4:52 PM, 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.
>
>
Python's, random module is your friend. I'd suggest looking at the
random.choice() function. As for the number of possibilities, if your codes
are not case sensitive, you'll have 10 + 26 = 36 possibilities for each
character/digit. 4 digits, so 36**4 possible codes.

Hugo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20120626/fafc3c8a/attachment.html>


More information about the Tutor mailing list