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.

Friday, September 5, 2025

Times tables Pascal code.

procedure TimTabP;
var
iocode:integer;
ch:char;
a,b,k,ans:integer;
tt:array[1..12] of integer;
begin
repeat
clrscr;
repeat
write('Enter the times table you want printed. ');
{$I-}
readln(a);
{$I+}
iocode:=ioresult;
until (iocode=0) and (a>0) and (a<13);
writeln;
randomize;
for k:=1 to 12 do
tt[k]:=0;

tt[1]:=random(12)+1;
repeat
tt[2]:=random(12)+1
until (tt[2]<>tt[1]);
repeat
tt[3]:=random(12)+1
until (tt[3]<>tt[1]) and (tt[3]<>tt[2]);
repeat
tt[4]:=random(12)+1
until (tt[4]<>tt[1]) and (tt[4]<>tt[2]) and (tt[4]<>tt[3]);
repeat
tt[5]:=random(12)+1
until (tt[5]<>tt[1]) and (tt[5]<>tt[2]) and (tt[5]<>tt[3]) and (tt[5]<>tt[4]);
repeat
tt[6]:=random(12)+1
until (tt[6]<>tt[1]) and (tt[6]<>tt[2]) and (tt[6]<>tt[3]) and (tt[6]<>tt[4])
and (tt[6]<>tt[5]);
repeat
tt[7]:=random(12)+1
until (tt[7]<>tt[1]) and (tt[7]<>tt[2]) and (tt[7]<>tt[3]) and (tt[7]<>tt[4])
and (tt[7]<>tt[5]) and (tt[7]<>tt[6]);
repeat
tt[8]:=random(12)+1
until (tt[8]<>tt[1]) and (tt[8]<>tt[2]) and (tt[8]<>tt[3]) and (tt[8]<>tt[4])
and (tt[8]<>tt[5]) and (tt[8]<>tt[6]) and (tt[8]<>tt[7]);
repeat
tt[9]:=random(12)+1
until (tt[9]<>tt[1]) and (tt[9]<>tt[2]) and (tt[9]<>tt[3]) and (tt[9]<>tt[4])
and (tt[9]<>tt[5]) and (tt[9]<>tt[6]) and (tt[9]<>tt[7]) and (tt[9]<>tt[8]);
repeat
tt[10]:=random(12)+1
until (tt[10]<>tt[1]) and (tt[10]<>tt[2]) and (tt[10]<>tt[3]) and (tt[10]<>tt[4])
and (tt[10]<>tt[5]) and (tt[10]<>tt[6]) and (tt[10]<>tt[7]) and (tt[10]<>tt[8])
and (tt[10]<>tt[9]);
repeat
tt[11]:=random(12)+1
until (tt[11]<>tt[1]) and (tt[11]<>tt[2]) and (tt[11]<>tt[3]) and (tt[11]<>tt[4])
and (tt[11]<>tt[5]) and (tt[11]<>tt[6]) and (tt[11]<>tt[7]) and (tt[11]<>tt[8])
and (tt[11]<>tt[9]) and (tt[11]<>tt[10]);
repeat
tt[12]:=random(12)+1
until (tt[12]<>tt[1]) and (tt[12]<>tt[2]) and (tt[12]<>tt[3]) and (tt[12]<>tt[4])
and (tt[12]<>tt[5]) and (tt[12]<>tt[6]) and (tt[12]<>tt[7]) and (tt[12]<>tt[8])
and (tt[12]<>tt[9]) and (tt[12]<>tt[10]) and (tt[12]<>tt[11]);

for k:=1 to 12 do
writeln(' ',a,' times ',tt[k],' = ',a*tt[k],' ');
writeln('');
write('Another? Y/N');
repeat
ch:=readkey
until (ch in ['Y','y','N','n']);
until (ch in ['N','n']);
end;