- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 获取随机字符串的方法 GetRandomString
function SuiJiString(const AWeiShu: Integer): string;
const
SourceStr: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var
MyRep: string;
I: Integer;
begin
Randomize;
for I := 1 to AWeiShu do
begin
//这里只所以必须加1,是因为SourceStr是从1开始的,而Random是从0开始的,SourceStr[0]就会报错,SourceStr[63]也会报错
MyRep := MyRep + SourceStr[Random(61)+1];
end;
Exit(MyRep);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.Caption:=SuiJiString(32);
end;