Created
November 13, 2015 21:47
-
-
Save glauco-basilio/d4ec98818d99f546efbf to your computer and use it in GitHub Desktop.
Gerador de CPF Válido
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var v = new CPFHelper().Ramdom(762).Dump(); | |
} | |
// Define other methods and classes here | |
public class CPFHelper | |
{ | |
public string GeraDV(string cpf) | |
{ | |
string digito = String.Empty; | |
int k, j, soma; | |
for (k = 0; k < 2; k++) | |
{ | |
soma = 0; | |
for (j = 0; j < 9 + k; j++) soma += int.Parse(cpf[j].ToString()) * (10 + k - j); | |
digito += (soma % 11 == 0 || soma % 11 == 1) ? 0 : (11 - (soma % 11)); | |
cpf+=digito; | |
} | |
return digito; | |
} | |
public IEnumerable<string> Ramdom(int qtd) | |
{ | |
var rnd = new Random(); | |
for(var i = 0; i< qtd-1;i++) | |
{ | |
var n = rnd.Next(100000000,999999999); | |
yield return n.ToString() + GeraDV(n.ToString()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment