你的程序会一直产生这样的错误结果:
1:=1;2:=2;3:=3;。。。。10:=10
你可以参考下面这样做
unit Unit1;
interface
uses
Windows, SysUtils, Forms, Dialogs, StdCtrls, Classes, Controls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
num:array[0..10] of byte;
implementation
{$R *.DFM}
Function rand(a:integer;b:integer):integer;//取随机数
begin
if b<a then result:=0 else result:=a+random(b-a+1);
end;
function asknum:byte;
var
a,b:byte;
begin
while 1>0 do begin
result:=rand(1,10);
b:=0;
for a:= 1 to 10 do if num[a]=result then b:=1;
if b=0 then break;
end;
end;
procedure clsNum;
var
a:byte;
begin
for a:= 1 to 10 do num[a]:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s:string;
a:byte;
begin
for a:=1 to 10 do num[a]:=asknum;
for a:=1 to 10 do s:=s+inttostr(a)+':='+inttostr(num[a])+#13#10;
showmessage(s);
clsNum;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;RandSeed:=rand(1,maxint);
clsNum;
end;
end.