function ran(AStart, AEnd, ACount: Integer): string; var I, X, A: Integer; AList: TList; begin AList := TList.Create; randomize; for I := AStart to AEnd do AList.Add(Pointer(I)); for I := 1 to ACount do begin X := Random(AList.Count); A := Integer(AList[X]); AList.delete(X); Result := Result + ',' + InttoStr(A); end; Result := copy(Result, 2, Length(Result)); AList.Free; end;
procedure TForm1.Button2Click(Sender: TObject); var i,ii,iii: integer; str: string; begin ii:=0; randomize; for iii:=1 to 3 do Begin repeat ii:=ii+1; i:=random(9); if ((i)>=0) and ((i)<=9) then str:=str+' '+inttostr(i); until ii>5; form1.Canvas.TextOut(10,10*iii,str); str:=''; ii:=0; end; end;
var
I, X, A: Integer;
AList: TList;
begin
AList := TList.Create;
randomize;
for I := AStart to AEnd do
AList.Add(Pointer(I));
for I := 1 to ACount do
begin
X := Random(AList.Count);
A := Integer(AList[X]);
AList.delete(X);
Result := Result + ',' + InttoStr(A);
end;
Result := copy(Result, 2, Length(Result));
AList.Free;
end;
var
i,ii,iii: integer;
str: string;
begin
ii:=0;
randomize;
for iii:=1 to 3 do
Begin
repeat
ii:=ii+1;
i:=random(9);
if ((i)>=0) and ((i)<=9) then
str:=str+' '+inttostr(i);
until ii>5;
form1.Canvas.TextOut(10,10*iii,str); str:='';
ii:=0;
end;
end;
http://blog.csdn.net/confucius/archive/2006/12/25/1460050.aspx