61 lines
1.6 KiB
Python
61 lines
1.6 KiB
Python
#! /usr/bin/env python3
|
|
|
|
# Generate one random mega million lotto number that is not an avoided number in the avoid.csv file.
|
|
# It simply redraw a number if the previous drawn number is an avoided number.
|
|
|
|
import secrets
|
|
import logging
|
|
import csv
|
|
|
|
def meganumber():
|
|
|
|
picks = []
|
|
# the mega million valid numbers are between 1 to 70 inclusive
|
|
choices = list(range(1,71))
|
|
|
|
for i in range(5):
|
|
logging.debug("choices are: %s", choices)
|
|
pick = secrets.choice(choices)
|
|
choices.remove(pick)
|
|
picks.append(pick)
|
|
|
|
logging.debug("choices left: %s", choices)
|
|
logging.debug("first five numbers: %s", picks)
|
|
picks.sort()
|
|
|
|
# the mega ball number is from 1 to 25
|
|
pick = secrets.choice(list(range(1,26)))
|
|
picks.append(pick)
|
|
|
|
return picks
|
|
|
|
def main():
|
|
|
|
# logging.basicConfig(level=logging.DEBUG, format = "[%(levelname)s] (%(threadName)-10s) %(message)s",)
|
|
logging.basicConfig(level=logging.INFO, format = "[%(levelname)s] (%(threadName)-10s) %(message)s",)
|
|
|
|
avoid = []
|
|
with open("avoid.csv", "r") as f:
|
|
reader = csv.reader(f)
|
|
for row in reader:
|
|
introw = []
|
|
for num in row:
|
|
introw.append(int(num))
|
|
avoid.append(introw)
|
|
|
|
for item in avoid:
|
|
logging.debug("before: %s", item)
|
|
item[0:5] = sorted(item[0:5])
|
|
logging.debug("after: %s", item)
|
|
|
|
pickone = meganumber()
|
|
while pickone in avoid:
|
|
print("the picked number is in the avoid list: %s, regenerate", pickone)
|
|
pickone = meganumber()
|
|
|
|
print(pickone)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|