# This program write 1 line of 12 random integers, each in the
# range from 1 - 100 to a text file.
# wohhie v2
import random
def generateNumbers():
# Open a file name data.txt
file = open('data.txt', 'w')
numRange = int(input("How Many to generate: "))
datalist = []
# Get a random number.
datalist = list(random.sample(range(100), numRange))
# write 12 random integers in the range of 1 - 100 on one line
# to the file.
datalist.sort()
#print(datalist)
for item in datalist:
line = str(item) + "\n"
file.write(line)
# Close the file.
file.close()
print("Data Written to data.txt")
generateNumbers()
from itertools import islice
import re
def ReadFile(filename, num):
file = open(filename + ".txt", 'r')
datalist = []
with open(filename + ".txt") as file:
datalist = list(islice(file, num))
# Close file
file.close()
# Updated datalist - Remove all new line
datalist = [el.replace('\n', '') for el in datalist]
# Store newlist into new file with the name of range
file = open(str(num) + ".txt", 'w')
for item in datalist:
line = str(item) + "\n"
file.write(line)
file.close()
print("Data Stored in " + str(num) + ".txt file")
ReadFile("10000000", 100)