This
extracts N numbers randomly from a value of 1-45.
Arrange
the six most frequently produced numbers in ascending order.
To run
.exe immediately, create "count.txt" with the exe file and run.
(Write the number of times to perform in count.txt.):
When
running as PowerShell or cmd, do as follows.
arg 1 :
Number of random extractions
arg 2:
How many sets of six will be created?
./lotto.exe
N Loop
ex)
./lotto.exe 10000 4
the
numbers 1-45, It randomly spins 10000 times to pick the six frequently produced
numbers, and then it repeats them four times to extract four sets.
Ex)
./lotto.exe
10000
./lotto.exe
10000 5
count.txt
10000
lotto.py
import sys
import os
import random
#DEFAULT_PROJECT_FILE_PATH = "./data"
MAX_COUNT = 10000000
DEFAULT_COUNT = 1000000
MIN_COUNT = 1
def Print(*args):
func_name = "[" + sys._getframe(1).f_code.co_name + "] "
for value in args:
if type(value) is str:
func_name = func_name + value
else:
func_name = func_name + str(value)
print(func_name)
class FileReadWriteClass :
def __init__(self, parent=None):
pass
def readFile(self, path): # only 1 line
# writedata.py
fp = open(path, mode='rt', encoding='utf-8')
data = fp.read()
fp.close()
return data
def writeFile(self, path, data):
fp = open(path, 'a+')
fp.write(data)
fp.write("\n")
fp.close()
class CalculatorClass :
calculatedNumbers = []
def __init__(self, parent=None):
pass
def calculator(self, count) :
numberDict = {}
index = 0
while index < count:
index += 1
num = random.randint(1, 45)
if num in numberDict:
numberDict[num] += 1
else:
numberDict[num] = 0
sixValues = sorted(numberDict.items(), reverse=True, key=lambda item: item[1])
index = 0
data = []
#print(sixValues)
for key in sixValues:
Print(key)
#print(key[0])
data.insert(index, key[0])
if index >= 5:
break
else:
index += 1
data.sort()
self.calculatedNumbers = data
return self.calculatedNumbers
def getValues(self) :
return self.calculatedNumbers
def main(value = None, loop = 1):
Print("Main")
calClass = CalculatorClass()
fileRWClass = FileReadWriteClass()
index = 0
while index < int(loop) :
if value is None :
count = fileRWClass.readFile("./count.txt")
else :
count = value
calClass.calculator(int(count))
result = calClass.getValues()
Print(count, " :: ", str(result))
fileRWClass.writeFile("./result.txt", count + " :: " + str(result))
index += 1
Print("Close")
if __name__ == "__main__":
if (len(sys.argv) <= 1) :
main()
elif (len(sys.argv) == 2) :
main(sys.argv[1])
elif (len(sys.argv) == 3) :
main(sys.argv[1], sys.argv[2])
else:
Print("Error")
create exe file
> pyinstaller lotto.py --onefile
#python #lotto #random number #example
No comments:
Post a Comment