Sunday, September 7, 2025

Random Generator Delphi Code

Random Generator Delphi

procedure TForm1.Button1Click(Sender: TObject);
label 1;
var
a:real;
ki,kup,k,x,y,nR,maxR:integer;
RGA:array[1..200] of integer;
Chos,errors1:boolean;
calcstr2,calcstr1,calcstr3:string[30];
begin
Canvas.Font.Style:=[fsbold];
Canvas.Font.Size:=12;
errors1:=false;
form1.hide;
form1.show;
try
nR:=strtoint(form1.edit1.Text);
MaxR:=strtoint(form1.edit2.Text);
except
errors1:=true;
end;
if (errors1=true) or
(nR<2) or (nR>maxR/2) or (nR>200)
then begin
form1.canvas.textout(0,100,'CHECK ENTRIES.');
goto 1
end;

for Ki:=1 to 100 do RGA[ki]:=0;
randomize;
x:=0;
y:=60;
RGA[1]:=random(maxR)+1;
for k:=2 to nR do begin
repeat
chos:=false;
RGA[k]:=random(maxR)+1;
for kup:=1 to (k-1) do
if RGA[k]=RGA[kup]
then chos:=true;
until chos=false;
end;

for k:= 1 to nR do begin
str(RGA[k],calcstr1);
a:=(k-1)/10;
if (a=round(a)) then begin
x:=0;
y:=y+25;
end;
if (a<>round(a)) then
x:=x+100;
form1.canvas.textout(x,y,'  '+calcstr1+'  ');
end;

1: end;

end.

No comments:

Post a Comment