08-04-2018, 05:45 PM
توليد أرقام عشوائبة يتم تحديدها وتعبئة(ComboBox)
---------------------------------------------------------------
procedure Shuffle(var aArray; aItemCount: Integer; aItemSize: Integer);
{ after Julian M Bucknall }
var
Inx: Integer;
RandInx: Integer;
SwapItem: PByteArray;
A: TByteArray absolute aArray;
begin
if (aItemCount > 1) then
begin
GetMem(SwapItem, aItemSize);
try
for Inx := 0 to (aItemCount - 2) do
begin
RandInx := Random(aItemCount - Inx);
Move(A[Inx * aItemSize], SwapItem^, aItemSize);
Move(A[RandInx * aItemSize], A[Inx * aItemSize], aItemSize);
Move(SwapItem^, A[RandInx * aItemSize], aItemSize);
end;
finally
FreeMem(SwapItem, aItemSize);
end;
end;
end;
-------------------------------------------------------------
procedure TForm12.Button4Click(Sender: TObject);
var
a: array[1..6] of Integer;
i: Shortint;
III:INTEGER;
begin
ComboBox2.Clear;
for i := 1 to High(a) do a[i] := i;
Shuffle(a, High(a), SizeOf(Integer));
for i := 1 to 6 do
BEGIN
ComboBox2.Items.Add(IntToStr(a[i]));
END;
ComboBox2.ItemIndex:=0;
end;
---------------------------------------------------------------
procedure Shuffle(var aArray; aItemCount: Integer; aItemSize: Integer);
{ after Julian M Bucknall }
var
Inx: Integer;
RandInx: Integer;
SwapItem: PByteArray;
A: TByteArray absolute aArray;
begin
if (aItemCount > 1) then
begin
GetMem(SwapItem, aItemSize);
try
for Inx := 0 to (aItemCount - 2) do
begin
RandInx := Random(aItemCount - Inx);
Move(A[Inx * aItemSize], SwapItem^, aItemSize);
Move(A[RandInx * aItemSize], A[Inx * aItemSize], aItemSize);
Move(SwapItem^, A[RandInx * aItemSize], aItemSize);
end;
finally
FreeMem(SwapItem, aItemSize);
end;
end;
end;
-------------------------------------------------------------
procedure TForm12.Button4Click(Sender: TObject);
var
a: array[1..6] of Integer;
i: Shortint;
III:INTEGER;
begin
ComboBox2.Clear;
for i := 1 to High(a) do a[i] := i;
Shuffle(a, High(a), SizeOf(Integer));
for i := 1 to 6 do
BEGIN
ComboBox2.Items.Add(IntToStr(a[i]));
END;
ComboBox2.ItemIndex:=0;
end;