Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, json
- class CPFGen(object):
- def __init__(self):
- self.cpf = []
- index = 10
- for i in range(9):
- digit = random.randint(0, 9)
- self.cpf.append(digit)
- for i in range(2):
- self.verificator(index)
- index += 1
- self.cpf.insert(3, ".")
- self.cpf.insert(7, ".")
- self.cpf.insert(11, "-")
- string = ""
- for i in range(len(self.cpf)):
- string += str(self.cpf[i])
- self.generated_cpf = string
- def verificator(self, index):
- sum = 0
- for i in range(len(self.cpf), 0, -1):
- sum += index * self.cpf[i - 1]
- index -= 1
- if sum % 11 <= 2:
- digit = 0
- else:
- digit = 11 - (sum % 11)
- self.cpf.append(digit)
- with open("CPFs.txt", "w") as file:
- data = {}
- for i in range(1000000):
- cpf = CPFGen()
- data[f"{i + 1}"] = cpf.generated_cpf
- print(f'{i + 1}°: {data[f"{i + 1}"]}')
- json_object = json.dumps(data)
- file.write(json_object)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement