delphi 分享三个随机字符串

时间:2023-12-30 08:15:44
uses math;

function GenID:String;
var
b, x: byte;
begin
Result := '{';
Randomize;
for b:= to do
begin
if Random() > then Result := Result + chr(RandomRange(,))
else Result := Result + chr(RandomRange(,));
end;
Result := Result + '-';
for x:= to do
begin
for b:= to do
begin
if Random() < then Result := Result + chr(RandomRange(,))
else Result := Result + chr(RandomRange(,));
end;
Result := Result + '-';
end;
for b:= to do
begin
if Random() < then Result := Result + chr(RandomRange(,))
else Result := Result + chr(RandomRange(,));
end;
Result := Result + '}';
end; function genkey :string;
const
Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var
S: string;
i, N: integer;
begin
Randomize;
S := '';
for i := to do begin
N := Random(Length(Chars)) + ;
S := S + Chars[N];
end;
result := S;
end; function genkey2(c:integer) :string;
const
Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
var
S: string;
i, N: integer;
begin
if c < then c := ;
Randomize;
S := '';
for i := to c do begin
N := Random(Length(Chars)) + ;
S := S + Chars[N];
end;
result := S;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
memo1.Lines.Add(GenID);
memo1.Lines.Add(genkey);
memo1.Lines.Add(genkey2());
end;