I've always liked uuid4
from uuid import uuid4
str(uuid4())[:4]
'0ca6'
On Tue, Jun 26, 2012 at 3:47 PM, Dave Angel d...@davea.name 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
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 -
On Tue, Jun 26, 2012 at 4:52 PM, Sithembewena Lloyd Dube
zebr...@gmail.comwrote:
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
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
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
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
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
import