1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
function GenerateCode(const aLength: integer): string;
var n,c1,c2 : integer;
c : char;
{$j+}
const
CCC : array[0..57] of char =
'cdefghjk234mnpqrstuvwxyz56789CDEFGHJK234MNPQRSTUVWXYZ56789';
{$J-}
Max = high(CCC);
begin
for n := 0 to Max do
begin
c1 := random(Max+1);
c2 := random(Max+1);
while c2 = c1 do
c2 := random(Max+1);
c := CCC[c1];
CCC[c1] := CCC[c2];
CCC[c2] := c;
end;
setlength(result, aLength);
for n := 1 to aLength do
begin
c := CCC[random(Max+1)];
while pos(C, result) <> 0 do
c := CCC[random(Max+1)];
result[n] := c;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
(Sender as TButton).Caption := GenerateCode(8);
end;
initialization
Randomize;
end. |
Partager