DELPHI XE 获取大写、小写、数字指定长度的随机数

redhat588
2020-08-26

function TfrmMain.RandomString(ALength: Integer): string;

const

  Seeds = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

var

  I, Index: Integer;

begin

  Result := '';

  Randomize;

  for I := 0 to ALength - 1 do

  begin

    Index := Random(Seeds.Length);

    Result := Result + Seeds.Chars[Index];

  end;

end;


procedure TfrmMain.Button2Click(Sender: TObject);

begin

  edtToken.Text := RandomString(43);

  ShowMessage(Length(RandomString(43)).ToString);

end;




阅读37