Sabtu, 01 Mei 2010

Blum Blum Shub in Delphi

2 days ago there is a friend that ask me about Blum-Blum Shub Random Number Generator method. I can ask her question at that time. So I post the code I got in this blog. Hope this can help.

Source :

procedure TForm1.Blum;

var

xo,i,p,q,start: Integer;

text_datei: TextFile;// ga dipake juga gpp

begin

start:=StrToInt(Form1.Edit1.Text);

p:=StrToInt(Form1.Edit3.Text);

q:=StrToInt(Form1.Edit5.Text);

Writeln(text_datei, 'Hasil');

Writeln(text_datei, 'Start: '+IntToStr(start));

Writeln(text_datei, 'Parameter P: '+IntToStr(p));

Writeln(text_datei, 'Parameter Q: '+IntToStr(q));

Writeln(text_datei, 'N=P*Q: '+IntToStr(p*q));

Writeln(text_datei, ' ');

for i := 1 to StrToInt(Form1.Edit2.Text) do begin

xo:=(start*start) mod (p*q); // start = s

if xo<0>

Form1.Ausgabe(xo);

start:=xo; end;

end;

//ini prosedur untuk menampilkan, baiknya diganti saja

procedure TForm1.Ausgabe(ergebnis: Integer); // ergebnis adalah parameter

begin

Writeln(text_datei ,IntToStr(a)+'. '+IntToStr(ergebnis));

Form1.Memo1.Lines.Append(IntToStr(ergebnis));

a:=a+1;

Form1.count;

end;