Python Lotto example (Get 6 numbers randomly)

Python Lotto example (Get 6 numbers randomly)


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__(selfparent=None):
        pass
    
    def readFile(selfpath):   # only 1 line
        # writedata.py
        fp = open(path, mode='rt'encoding='utf-8')
        data = fp.read()
        fp.close()
        return data
    def writeFile(selfpathdata):
        fp = open(path, 'a+')
        fp.write(data)
        fp.write("\n")
        fp.close()

class CalculatorClass :
    calculatedNumbers = []
    
    def __init__(selfparent=None):
        pass
    
    def calculator(selfcount) :
        numberDict = {}
        index = 0
        while index < count:
            index += 1
            num = random.randint(145)
            if num in numberDict:
                numberDict[num] += 1
            else:
                numberDict[num] = 0
        sixValues = sorted(numberDict.items(), reverse=Truekey=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 = Noneloop = 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

알뜰폰 삼성페이 교통카드 '한도 초과' 오류(등록 불가 오류) 해결방법

sk7mobile 알뜰폰 삼성페이 교통카드 등록 시, 한도 초과 문제 해결방법 skt usim 해킹 사건으로 인해 sk7mobile 알뜰폰을 사용하는 저도 usim을 바꾸고 나니 삼성페이 교통카드가 등록이 안되더라구요...  삼성페이 교통카드 기능 은...