Arsip: Random bilangan integer (n)


by doditali in Articles more 15 years ago 1389
saya gunakan source ini utk mengacak bilangan integer dari -n ... n
mudah-mudahan membantu ;
procedure Shuffle(var baris; hitung_item: Integer; ukuran_item: Integer);
var
I: Integer;
Randi: Integer;
item_swap: PByteArray;
A: TByteArray absolute baris;
begin
if (hitung_item > 1) then
begin
GetMem(item_swap, ukuran_item);
try
for I := 0 to (hitung_item - 2) do
begin
Randi := Random(hitung_item - I);
Move(A[I  ukuran_item], item_swap^, ukuran_item);
Move(A[Randi   ukuran_item], A[I  ukuran_item], ukuran_item);
Move(item_swap^, A[Randi   ukuran_item], ukuran_item);
end;
finally
FreeMem(item_swap, ukuran_item);
end;
end;
end;

saya gunakan komponen listbox utk menampilkan bilangan integer yang random serta menggunakan komponen button utk merandom


procedure TForm1.tbl_BuatBilanganRandomClick(Sender: TObject);
var
a: array[-9..40] of Integer; // disini anda dapat mengganti misalnya [0..40] ato
[-60..900]
i: Shortint;
begin
listbox1.Items.Clear;
Randomize;
for i := Low(a) to High(a) do
a[i] := i;
Shuffle(a, High(a), SizeOf(Integer));
for i := 1 to High(a) - 1 do
ListBox1.Items.Add(IntToStr(a[i]));
end;

Silahkan dicoba.

Local Business Directory, Search Engine Submission & SEO Tools FreeWebSubmission.com SonicRun.com