Program LInier menggunakan borlan delphi7
Rumus Kongruen Linier : Zi+1= (a . Zi + c) mod m
bilangan random yang dihasilkan = Z1, Z2, Z3, Z4, …...
Metode ini banyak digunakan di dalam program komputer,
ketentuan untuk memilih Z0, a, c, dan m sama dengan
metode Multiplicative.
unit UKongLinier;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
Button1: TButton;
GroupBox1: TGroupBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
ListBox1: TListBox;
Label6: TLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var a,b,z0,m,i,n,hasil,z:integer;
begin
ListBox1.Items.Clear;
a:=StrToInt(Edit1.Text);
b:=StrToInt(Edit2.Text);
z0:=StrToInt(Edit3.Text);
m:=StrToInt(Edit4.Text);
n:=StrToInt(Edit5.Text);
for i:=1 to n do
//for z:=1 to 4 do
begin
z0:=(a*z0+b) mod m;
hasil:=z0;
ListBox1.Items.Add(IntToStr(hasil));
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
Edit4.Clear;
Edit5.Clear;
ListBox1.Items.Clear;
edit1.SetFocus;
end;
end.
Tidak ada komentar:
Write komentar