function GetRandomPassword(ALen: Integer): string; //你把6传进去就好了 var str: string; begin Randomize; //string with all possible chars str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; Result := ''; repeat Result := Result + str[Random(Length(str)) + 1]; until (Length(Result) = ALen) end;
var
str: string;
begin
Randomize;
//string with all possible chars
str := 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
Result := '';
repeat
Result := Result + str[Random(Length(str)) + 1];
until (Length(Result) = ALen)
end;
如果你真想这样的话,就用Random吧,然后建一个新的数据库或文件,记录已经存在的密码,查询原数据库也可以!
psw:=random();
if recordcount=0 then
insert...
else
continue;
uses ComObj;procedure TForm1.Button1Click(Sender: TObject);
var
s :string;
begin
s:=CreateClassID;
s:=Copy(s,2,6);
showmessage(s);
end;