def GenerateRandomString(len, basechars = []): if (basechars == []): x = range(ord('a'), ord('z') + 1) x.extend(range(ord('A'), ord('Z') + 1)) x.extend(range(ord('0'), ord('9') + 1)) basechars = [chr(i) for i in x] ret = '' for i in range(len): ret += random.choice(basechars) return ret