[تمرين] مولد ارقام عشوائية (RandomGenerator)
#8
توليد أرقام عشوائبة يتم تحديدها وتعبئة(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;
الرد


الردود في هذا الموضوع
RE: [تمرين] مولد ارقام عشوائية (RandomGenerator) - بواسطة osama23485555 - 08-04-2018, 05:45 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم