Take the 2-minute tour ×  I'd like to use Python's random.choice
seeded with a HMAC-SHA1 tag to generate a MAC encoded in a
variable set of chars.  import random, hmac, hashlib, string
SECRET = 'something secret' MESSAGE = 'some message' MAC_CHARS =
string.ascii_letters + string.digits MAC_LEN = 10
random.seed(hmac.new(SECRET, MESSAGE, hashlib.sha256).digest())
mac = ''.join([random.choice(MAC_CHARS) for _ in
xrange(MAC_LEN)]) random.seed()  # resets seed from /dev/random
Are the properties of the mac variable at equivalent to that of
an HMAC tag?  share|improve this question Do you want to tell us
more about why you want to use Python's random.choice in this
way? There might be a better solution. (P.S. Welcome to
Crypto.SE!) –  D.W. Apr 18 '13 at 10:29 Thanks! Indeed there
probably are. In this case, I'm trying to pick randomly from a
custom alphabet. I thought of doing ALPHABET[MAC mod
ALPHABET_SIZE], but it seems like some elements in the alphabet
will get picked over others. I'll post the problem I'm t