Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:function gerarCpf() {const n1 = aleatorio(), n2 = aleatorio(), n3 = aleatorio(), d1 = dig(n1, n2, n3);var cpf = `${n1}${n2}${n3}${d1}${dig(n1, n2, n3, d1)}`;if (!TestaCPF(cpf)) return gerarCpf(); return cpf;}; function dig(n1, n2, n3, n4) {let nums = n1.split("").concat(n2.split(""), n3.split("")), x = 0; if (n4) nums[9] = n4; for (let i = (n4 ? 11:10), j = 0; i >= 2; i--, j++) {x += parseInt(nums[j]) * i;}; return (y = x % 11) < 2 ? 0 : 11 - (y = x % 11);};function aleatorio() {return ("" + Math.floor(Math.random() * 999)).padStart(3, '0');};function TestaCPF(strCPF) {var Soma = 0;var Resto; if (strCPF == "00000000000") {return false;};for (i=1; i<=9; i++) {Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (11 - i);};Resto = (Soma * 10) % 11;if ((Resto == 10) || (Resto == 11)) {Resto = 0};if (Resto != parseInt(strCPF.substring(9, 10))) {return false};Soma = 0;for (i = 1; i <= 10; i++) { Soma = Soma + parseInt(strCPF.substring(i-1, i)) * (12 - i); };Resto = (Soma * 10) % 11;if ((Resto == 10) || (Resto == 11)) {Resto = 0;};if (Resto != parseInt(strCPF.substring(10, 11))) {return false;};return true;};prompt('', gerarCpf());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement