python生成随机二进制文件
1 import random 2 def genFile(filename,block=1,size=1): 3 f=open(filename,"wb") 4 content="" 5 #for j in range(1024*1024): 6 for j in range(1): 7 content=bytes(b"") 8 #for i in range(1024): 9 for i in range(1): 10 c=chr(random.randint(0,255)).encode('utf-8') 11 content=content+c 12 f.write(content) 13 14 print(len(sys.argv)) 15 if len(sys.argv) != 2: 16 print("usage:\t"+sys.argv[0]+"\toutfilename") 17 sys.exit(1) 18 genFile(sys.argv[1],1024,1024*1024)