So, I've been trying to make a random series generator with the given numbers using an array: so the possibilities are: [0-9, 0-9, 0-9, 0 - 59, 0-9, 0-9, 0-9]. The only problem is that I want that all the series aren't even 75% the same (no more than 2 numbers the same). So here are some examples: Good: [1, 1, 1, 1, 1, 1, 1] [2, 2, 1, 2, 1, 2, 2] Not good: [1, 1, 1, 1, 1, 1, 1] [2, 2, 1, 2, 1, 2, 1]
So, if there are fewer than 2 numbers the same it deletes the second one. And the second problem is that I want 10,000 of these series.
Sorry if I didn't explain it well, the code would probably explain what I tried to explain.
TRIGGER WARNING!! CODE ISN'T EFFICIENT AT ALL!!
TOTAL_SERIES = 10000
placement_amount = [9, 9, 9, 59, 9, 9, 9]
all_series = []
start = time.time()
fail = 0
success = 0
def create_image():
global fail, success
series = []
for i in range(len(placement_amount)):
series.append(random.randint(0, placement_amount[i]))
for i in all_series:
count = 0
for j in range(len(i)):
if series[j] == i[j]:
count += 1
if count > 2:
fail += 1
return;
success += 1
all_series.append(series)
def clear():
os.system('cls')
while len(all_series) < TOTAL_SERIES:
clear()
print('Success: ' + str(success))
print('Failed: ' + str(fail))
current = time.time()
delta = current - start
hour = str(math.floor(delta / 3600))
minutes = str(math.floor(delta / 60) % 60)
seconds = str(math.floor(delta) % 60)
print(hour + ':' + minutes + ':' + seconds)
create_image()
for i in all_series:
print(i)
The code technically works but it takes around 1 hour to generate 400 of these since the longer it runs the harder it takes to find a series that follows the rules.
So, my question is how do I make it more efficient and so it will make 10,000 series the fastest a code can.
What I've tried so far: Tried adding cuda so I'll be able to run the code on a gpu making it faster (have python 32-bit so can't) Tried creating a few threads where each generates 10,000/threads amount and then run a code that deletes all the ones who don't follow the rules (the code just got stuck).
I'm open to hear how I can try these again but with a correct code or anything that will make it efficient.
Aucun commentaire:
Enregistrer un commentaire