如何生成一个N位长度的随机字符串

解决方案 »

  1.   

    function RandomString(mChars: string; mLength: Integer): string;
    var
      I: Integer;
    begin
      Randomize;
      Result := '';
      if mChars = '' then Exit;
      for I := 1 to mLength do
        Result := Result + mChars[Random(Length(mChars)) + 1];
    end; { RandomString }procedure TForm1.Button1Click(Sender: TObject);
    begin
      Caption := RandomString('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', 16);
    end;
      

  2.   

    用 CoCreateGuid 生成多个GUID,每次都会不一样每个长度好像是32。
    然后合并
      

  3.   

    同意这个:zswangII(伴水清清)(一贴不灌,何以灌天下?简单适用