测一下时间! 字串的长度无限制
{-------------------------------------------------------------------------------
过程名: GetRandomNumList
作者: Kook
日期: 2006.03.31
参数: const ALen: integer (需要输出的字串的长度, 长度无限制)
AOutCount: integer (需要输出的个数)
VStringList: TStringList (输出字串)
返回值: 无
-------------------------------------------------------------------------------}
procedure GetRandomNumList(const ALen: integer
const AOutCount: Integer;
VStringList: TStringList)
var
Nums: array of integer;
m, n, x, Loop, Len: integer;
i, j, MaxNum: integer;
FmtStr: string;
begin
if ALen > 5 then
begin
Loop := ALen div 5;
for j := 1 to Loop do
GetRandomNumList(5, AOutCount, VStringList);
Len := ALen mod 5;
GetRandomNumList(Len, AOutCount, VStringList);
Exit;
end
else
if ALen < 1 then
Exit;
FmtStr := '%.' + IntToStr(ALen) + 'd';
MaxNum := StrToInt('1' + Format(FmtStr, [0]));
SetLength(Nums, MaxNum);
for i := 0 to MaxNum - 1 do
Nums := i;
Randomize;
for i := 1 to MaxNum do
begin
m := Random(MaxNum);
n := Random(MaxNum);
x := Nums[m];
Nums[m] := Nums[n];
Nums[n] := x;
end;
FmtStr := '%.' + IntToStr(ALen) + 'd';
if VStringList.Count = 0 then
begin
for i := AOutCount - 1 downto 0 do
VStringList.Add(Format(FmtStr, [Nums]));
end
else
begin
for i := AOutCount - 1 downto 0 do
VStringList := Format(FmtStr, [Nums]) + VStringList;
end;
end;