Randomize initializes the built-in random number generator with a random value (obtained from the system clock). The random number generator should be initialized by making a call to Randomize, or by assigning a value to RandSeed.Do not combine the call to Randomize in a loop with calls to the Random function. Typically, Randomize is called only once, before all calls to Random.
Obtain from delphi help?Can U expatiate it in Chinese,Thanks!
写个小程序测试看看; procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin listbox1.Clear ; for i:=1 to 10 do begin listbox1.Items.Add(inttostr(random(20))); end; end; 关闭你的程序,然后重新运行;再点BOTTON1你就会发现和上次运行产生的随即数一样的;
procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin randomize;//加上再看看?? listbox1.Clear ; for i:=1 to 10 do begin listbox1.Items.Add(inttostr(random(20))); end; end;
ramdonize把当前系统时间放入随机数生成器来产生随机数,不同的时间产生的数不一样:)
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
begin
listbox1.Clear ;
for i:=1 to 10 do
begin
listbox1.Items.Add(inttostr(random(20)));
end;
end;
关闭你的程序,然后重新运行;再点BOTTON1你就会发现和上次运行产生的随即数一样的;
var
i:integer;
begin
randomize;//加上再看看??
listbox1.Clear ;
for i:=1 to 10 do
begin
listbox1.Items.Add(inttostr(random(20)));
end;
end;