import os, random, glob
list_num = range(1, 41)
file_list = glob.glob('*.*')
for file_name in file_list:
file_type = file_name.split('.')[-1]
randint = str(random.choice(list_num))
new_name = randint + '.' + file_type
os.rename(file_name, new_name)
list_num.remove(int(randint))