生成十位数:
s = str(random.randint(0, 99999999)).zfill(10)
生成并保证单一性:
def get_s():import randomfor i in range(0, 10000000):s = str(random.randint(0, 99999999)).zfill(10)test_rkeys = r_conn.hget('gbrgbr46', s)if test_rkeys == None:r_conn.hset('gbrgbr46', s, '1')else:continueprint('生成随机码成功')print(s,'随机码')return s