procedure SelectTenNumber;
function IsExist(No:integer):Boolean;
var
i:integer;
begin
result:=false;
for i:=0 to 9 do
begin
if MyArray=No then
begin
result:=true;
break;
end;
end;
end;
var
z:integer;
stemp:integer;
begin
for z:=0 to 9 do
begin
repeat
Randomize;
stemp:=random(40+1);//注意random的取值范围是 0 <= X < Range
until IsExist(stemp)=false;
MyArray[z]:= stemp;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Exist : set of 0..40
//定义一个范围在0~40之间的集合
x, Count : integer ;
begin
Exist := []
//集合最初没元素
Count := 0
//计数=0
while Count<10 do //计数不足10个时继续
begin
x := random(41)
//随机数
if not (x in Exist) //未出现过,则集合中没有
then begin
Exist := Exist + [x]
//往集合中加这个数
Inc(Count)
//增加计数
end ;
end ;
for x:=0 to 40 do
if x in Exist then Caption := Caption + ' - ' + InttoStr(x)
//输出
end;