Arsip: Random bilangan integer (n)


by doditali in Articles more 19 years ago 2140
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.

Coinfest

Pascal Indonesia is Coinfest Asia 2024's official community partner! 🀝
β˜€οΈ Take part in Asia’s immersive Web3 festival, where innovation meets adoption.
🎟 Get your tickets at www.coinfest.asia and use our special promo code : CA24PASCALINDO to get 10% off!

Why Coinfest Asia?
● Unconventionally Engaging
Our immersive setting and programming leave you with more memory markers than any other event
● Dive into Emerging Markets
Get connected in Southeast Asia; the fastest-growing Web3 region in the world
● Jump straight into Adoption
Foster collaborations directly in Indonesia where there are 437k new crypto users each month

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