给你个函数,产生N个从MINNO到MAXNO中选SELECTNO个号码的函数; function Roule1L(n,maxno,minno,selectno:byte):String; var selectnoarr:array of integer; tmp,i,j:byte; tmpstr,tmpstr1:string; begin SetLength(selectnoarr,maxno-minno+1); for i:=minno to maxno do selectnoarr[i-minno]:=i; Randomize; for i:=1 to n do begin for j:=1 to selectno do begin tmp:=RandomFrom(selectnoarr); while (Pos(RightStr(Format('0%d',[tmp]),2),tmpstr)>0) do begin tmp:=RandomFrom(selectnoarr); end; tmpstr:=RightStr(Format('0%d',[tmp]),2)+tmpstr; end; tmpstr1:=tmpstr+','+tmpstr1; tmpstr:=''; end; result:=Copy(tmpstr1,1,Length(tmpstr1)-1); end;
function Roule1L(n,maxno,minno,selectno:byte):String;
var
selectnoarr:array of integer;
tmp,i,j:byte;
tmpstr,tmpstr1:string;
begin
SetLength(selectnoarr,maxno-minno+1);
for i:=minno to maxno do
selectnoarr[i-minno]:=i;
Randomize;
for i:=1 to n do
begin
for j:=1 to selectno do
begin
tmp:=RandomFrom(selectnoarr);
while (Pos(RightStr(Format('0%d',[tmp]),2),tmpstr)>0) do
begin
tmp:=RandomFrom(selectnoarr);
end;
tmpstr:=RightStr(Format('0%d',[tmp]),2)+tmpstr;
end;
tmpstr1:=tmpstr+','+tmpstr1;
tmpstr:='';
end;
result:=Copy(tmpstr1,1,Length(tmpstr1)-1);
end;
解决的办法是:在主程序(主窗体)开始,调用初始化函数。然后在需要的地方调用产生随机数的函数。