Re: [Tutor] Generating random alphanumeric codes

2012-07-04 Thread Japhy Bartlett
I've always liked uuid4 >>> from uuid import uuid4 >>> str(uuid4())[:4] '0ca6' On Tue, Jun 26, 2012 at 3:47 PM, Dave Angel wrote: > On 06/26/2012 03:47 PM, Martin A. Brown wrote: > > Hello, > > > > : Would anyone have tips on how to generate random 4-digit > > : alphanumeric codes in python?

Re: [Tutor] Generating random alphanumeric codes

2012-06-26 Thread Dave Angel
On 06/26/2012 03:47 PM, Martin A. Brown wrote: > Hello, > > : 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? > > Here are some thoughts that come to my mind: > > import string >

Re: [Tutor] Generating random alphanumeric codes

2012-06-26 Thread Martin A. Brown
Hello, : 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? Here are some thoughts that come to my mind: import string import random # -- technique #1, using random.choice pri

Re: [Tutor] Generating random alphanumeric codes

2012-06-26 Thread taserian
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,

Re: [Tutor] Generating random alphanumeric codes

2012-06-26 Thread taserian
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 i

Re: [Tutor] Generating random alphanumeric codes

2012-06-26 Thread Hugo Arts
On Tue, Jun 26, 2012 at 4:52 PM, Sithembewena Lloyd Dube 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.

[Tutor] Generating random alphanumeric codes

2012-06-26 Thread Sithembewena Lloyd Dube
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