Advertisement
pedrolemoz

CPF Generator V3

Sep 14th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. import random, json
  2.  
  3. class CPFGen(object):
  4.     def __init__(self):
  5.         self.cpf = []
  6.         index = 10
  7.        
  8.         for i in range(9):
  9.             digit = random.randint(0, 9)
  10.             self.cpf.append(digit)
  11.  
  12.         for i in range(2):
  13.             self.verificator(index)
  14.             index += 1
  15.            
  16.         self.cpf.insert(3, ".")
  17.         self.cpf.insert(7, ".")
  18.         self.cpf.insert(11, "-")
  19.        
  20.         string = ""
  21.        
  22.         for i in range(len(self.cpf)):
  23.             string += str(self.cpf[i])
  24.        
  25.         self.generated_cpf = string
  26.    
  27.     def verificator(self, index):
  28.         sum = 0
  29.         for i in range(len(self.cpf), 0, -1):
  30.             sum += index * self.cpf[i - 1]
  31.             index -= 1
  32.        
  33.         if sum % 11 <= 2:
  34.             digit = 0
  35.         else:
  36.             digit = 11 - (sum % 11)
  37.        
  38.         self.cpf.append(digit)
  39.  
  40. with open("CPFs.txt", "w") as file:
  41.     data = {}
  42.     for i in range(1000000):
  43.         cpf = CPFGen()
  44.         data[f"{i + 1}"] = cpf.generated_cpf
  45.         print(f'{i + 1}°: {data[f"{i + 1}"]}')
  46.     json_object = json.dumps(data)
  47.     file.write(json_object)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement