import random with open("1.txt", "w") as f: f.write("100000 1000000000\n") for i in range(10**5): f.write(str(random.randint(1, 10**9)) + " ")