- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi Memo1 行随机打乱
procedure ShuffleStrings(List: TStrings; MoveCount: Integer = 0);
var
i, N, C: Integer;
Index1, Index2: Integer;
Str: string;
Obj: TObject;
begin
List.BeginUpdate;
try
C:=List.Count;
N:=MoveCount;
if N <= 0 then N:=C*C-C;
for i:=0 to N do begin
Index1:=Random(C);
Index2:=Random(C);
Str:=List.Strings[Index1];
Obj:=List.Objects[Index1];
List.Strings[Index1]:=List.Strings[Index2];
List.Objects[Index1]:=List.Objects[Index2];
List.Strings[Index2]:=Str;
List.Objects[Index2]:=Obj;
end;
finally
List.EndUpdate;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShuffleStrings(Memo1.Lines);
end;