Skip to content

Instantly share code, notes, and snippets.

@biliboss
Last active December 30, 2015 18:58
Show Gist options
  • Save biliboss/7870636 to your computer and use it in GitHub Desktop.
Save biliboss/7870636 to your computer and use it in GitHub Desktop.
function gerarCPF: string;
//http://www.geradorcpf.com/algoritmo_do_cpf.htm
var
cpf: string;
i: integer;
procedure Digito(Var cpf: string);
var
d: integer;
i: integer;
begin
d := 0;
//length(cpf) + 1:
for i := length(cpf) + 1 downto 2 do
d := d+ (StrToInt(cpf[length(cpf) + 2 - i]) * i);
d := 11 - (d mod 11);
d := ifThen(d > 9, 0, d);
cpf := cpf + intToStr(d);
end;
begin
cpf := '';
Randomize;
for i := 1 to 9 do
cpf := cpf + IntToStr(Random(9));
Digito(cpf);//digito 1
Digito(cpf);//digito 2
result := cpf;
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment