import random
foo = range(590, 599+1)#590,599之间生成12个数,和等于7126
str1 = [] # 目标列表
i = 0 # 生成次数
j = 0
while sum(str1) != 7126:
i += 1
str1 = random.choices(foo, k=12)
with open('id.txt') as inf,open('sql.txt','w') as outf:
for line in inf:
print('update table set value='"'",str1[j],"'"' where id='"'",line.replace("\n",''),"'"';',file=outf)
j+=1
590,599之间生成12个数,和等于7126.
id.txt 对应12个id,生成sql语句,写入到sql.txt文件中