dimanche 18 juillet 2021

How to speed up 8 digits combination numbers in python [duplicate]

I Have Code Like this

n = 8
Num = set()
start = 0
end = 10**n

while start < end:
  x = ''.join(['{}'.format(randint(0, 9)) for num in range(0, n)])
  if x not in Num:
    start += 1
    Num.add(x)

Which gave me result like this:

46282449
76709352
92922406

The point of the code above is that I want to produce all combinations of the 8 digit numbers, which means there are about 100 million combinations. My problem is this code takes a lot of time to process (until now this code has taken up to 7 hours more and has not stopped). Can someone give me advice on how to optimize this code?

Aucun commentaire:

Enregistrer un commentaire