import random
def randoms():
ran = random.sample(range(1, 470),440) #440为生成的随机数的数量
return ran
data=randoms()
file = open('D:\\graduation design data\\deep-learning-for-image-processing-master\\data_set\\crack_data\\VOCdevkit\\VOC2012\\ImageSets\\Segmentation\\train.txt', 'w')
for i in range(0, 439):
file.write((str(data[i])) + '\n')
file.close()
range()为生成随机数的范围,file为text文件所在的路径。复制黏贴修改好相关的参数后直接运行即可。