function btnGenerateClick(intMAX_PW_LEN:integer;intMAX_PW_num:integer): string;{max length of generated password} //const // intMAX_PW_LEN = 8; var i,h: Byte; s,p,str1,str2: string; begin {if you want to use the "A..Z" characters} if intMAX_PW_LEN<>0 then s := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' else s := ''; {if you want to use the "a..z" characters} // if form1.radiobutton1.Checked then // s := s + 'abcdefghijklmnopqrstuvwxyz'; {if you want to use the "0..9" characters} if intMAX_PW_num<>0 then begin p :='0123456789'; for h:=0 to intMAX_PW_num-1 do str1:=str1+p[Random(Length(p)-1)+1]; end; if (s = '') and (p='') then exit; Result := ''; if intMAX_PW_num=0 then p:=''; for i := 0 to intMAX_PW_LEN-1 do str2 :=str2+s[Random(Length(s)-1)+1]; result:=str2+str1; end;btnGenerateClick(intMAX_PW_LEN:integer;intMAX_PW_num:integer)参数分别是要返回的数字和字母的位数
delphi中有生成随机数的函数 Begin Randomize; edit1.Text:=IntToStr(Random(10000000000)); end;
//const
// intMAX_PW_LEN = 8;
var
i,h: Byte;
s,p,str1,str2: string;
begin
{if you want to use the "A..Z" characters}
if intMAX_PW_LEN<>0 then
s := 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
else
s := ''; {if you want to use the "a..z" characters}
// if form1.radiobutton1.Checked then
// s := s + 'abcdefghijklmnopqrstuvwxyz'; {if you want to use the "0..9" characters}
if intMAX_PW_num<>0 then
begin
p :='0123456789'; for h:=0 to intMAX_PW_num-1 do
str1:=str1+p[Random(Length(p)-1)+1];
end;
if (s = '') and (p='') then exit; Result := '';
if intMAX_PW_num=0 then
p:='';
for i := 0 to intMAX_PW_LEN-1 do
str2 :=str2+s[Random(Length(s)-1)+1];
result:=str2+str1;
end;btnGenerateClick(intMAX_PW_LEN:integer;intMAX_PW_num:integer)参数分别是要返回的数字和字母的位数
delphi中有生成随机数的函数
Begin
Randomize;
edit1.Text:=IntToStr(Random(10000000000));
end;