I am trying to make a lottery program for my school (we have an economic system).
My program generates numbers and saves it off into a text file. When I want to "pull" numbers out of my generator I want it to ensure that there is a winner.
Q: How do I have Python select a random line out of my text file and give my output as that number?
How do I have python select a random line out of my text file and give my output as that number?
Assuming the file is relatively small, the following is perhaps the easiest way to do it:
import random
line = random.choice(open('data.txt').readlines())