t1 = timeit.Timer(
    "''.join(random.choice('0123456789abcdef') for n in xrange(30))",
    'import random')
t2 = timeit.Timer('binascii.b2a_hex(os.urandom(15))', 'import os, binascii')
t3 = timeit.Timer("'%030x' % random.randrange(16**30)", 'import random')
for t in (t1, t2, t3):
    t.timeit()
Most lightweight way to create a random string and a random hexadecimal number