Every time I need to quickly generate some randomness I keep hacking something new together. This should hopefully save some time, if I remember that I have it in my toolbox. :)
#!/usr/bin/env python2.7
chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
import random
import sys
if __name__ == "__main__":
end = 1000
if len(sys.argv[:]) > 1:
_end = int(sys.argv[1])
if _end > 0:
end = _end
res = ""
for i in range(0, end):
res += chars[random.randint(0,len(chars)-1)]
print res