// Beispiel 1 ------------------------------------
type
TArray = array [0 .. 19] of Byte;
var
MyArray: TArray;
procedure Shuffle(var aArray: TArray);
var
i, j: Integer;
hlp: Byte;
begin
for i := Low(aArray) to High(aArray) do
begin
j := i + Random(Length(aArray) - i + Low(aArray));
hlp := aArray[j];
aArray[j] := aArray[i];
aArray[i] := hlp;
end;
end;
// Mit Listboxen zwecks Anzeige
procedure TForm1.Button1Click(Sender: TObject);
var
i: Integer;
begin
// Array füllen zum Testen
for i := 0 to High(MyArray) do
MyArray[i] := Succ(i);
// Anzeigen
ListBox1.Items.Clear;
ListBox2.Items.Clear;
for i := 0 to High(MyArray) do
ListBox1.Items.Add(IntToStr(MyArray[i]));
// Mischen
Randomize;
Shuffle(MyArray);
// Mischung anzeigen
for i := 0 to High(MyArray) do
ListBox2.Items.Add(IntToStr(MyArray[i]));
end;
// Beispiel 2 ------------------------------------
const
Arrays = 3;
Content = 10;
type
TNewArray = array [0 .. Arrays - 1, 0 .. Content - 1] of Integer;
var
NewArray: TNewArray;
procedure NewShuffle(var aArray: TNewArray; w: Integer);
var
i, j, hlp: Integer;
begin
for i := Low(aArray) to High(aArray) do
begin
j := i + Random(Length(aArray[w]) - i + Low(aArray[w]));
hlp := aArray[w][j];
aArray[w][j] := aArray[w][i];
aArray[w][i] := hlp;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
x, y: Integer;
begin
// Arrays füllen zum Testen
for x := 0 to pred(Arrays) do
for y := 0 to pred(Content) do
NewArray[x][y] := Succ(y);
// Mischen
Randomize;
for y := 0 to pred(Arrays) do
NewShuffle(NewArray, y);
end;