procedure Randomize;
var
Counter: Int64;
begin
if QueryPerformanceCounter(Counter) then
RandSeed := Counter
else
RandSeed := GetTickCount;
end;
如果系统不支持精确时间,则用GetTickCount
GetTickCount是非常大的单位,在运行很多行代码的情况下是不变的,所以下面代码有问题:
for I := 0 to 1000 do
begin
Randomize;
...
end;
var
Counter: Int64;
begin
if QueryPerformanceCounter(Counter) then
RandSeed := Counter
else
RandSeed := GetTickCount;
end;
如果系统不支持精确时间,则用GetTickCount
GetTickCount是非常大的单位,在运行很多行代码的情况下是不变的,所以下面代码有问题:
for I := 0 to 1000 do
begin
Randomize;
...
end;