import?random
with?open('a.txt','r')?as?f:
with?open('b.txt','w')?as?f2:
lines=f.readlines()
flen=len(lines)-1
for?i?in?range(1,random.randint(0,flen)):
f2.write(lines[random.randint(0,flen)])