python实现指定长度的随机数

import random
def random_20char(string,length):
    for i in range(length):
        x = random.randint(1,2)
        if x == 1:
            y = str(random.randint(0,9))
        else:
            y = chr(random.randint(97, 122))
        string.append(y)
    string = ''.join(string)
    return string

if __name__ == '__main__':
    string = []
    length = 20
    qqq = random_20char(string,length)
    print(qqq)

你可能感兴趣的:(python)