I'm an introductory Python student, but it's been blocked for about a week.
I want to create n sets of 6 lotto numbers (set to 3 sets in the code below), but if I make it as below, the computer will have a hard time even if the number of n exceeds 5 million. Is there any way?
import random
import itertools
buy_num_list = [ ]
buy_pool = list(itertools.combinations(list(range(1, 46)), 6))
for i in range(3):
buy_num_list = random.choice(buy_pool)
buy_pool.remove(buy_num_list)
print(buy_num_list)
import random
import itertools
buyPool = [] # PurchaseList
cntLimit = 10000 #Define how many times to proceed
LottoPool = list(itertools.combinations(list(range(1, 46)), 6)) # LottoPool
print(len(LottoPool), 'is Ready') #LottoPOOL count = 8145060
for cnt in range(cntLimit):
nowNumber = random.choice(LottoPool)
If nowNumber not in buyPool: # If it's not the number you purchased,
print(nowNumber)
buyPool.append(nowNumber) #Add to purchase list
© 2024 OneMinuteCode. All rights reserved.