program population;
const
total = 100; { Number of people in population}
stages = 15; { Number of stages}
Numsim = 5; {Number of simulations}
count = 3; {Number of encounters per stage}
tol = 0.28; {if sum on dice is less than 5 and person interacts with infected person, infection occurs}
var y: array[1..total] of integer; {Y holds the infection status of population}
a: array[1..stages,1..Numsim] of integer; {a holds the number of infected people at each stage}
sim,i,j,k,m,n,inner: integer; {each column of a is one simulation}
FileName : string; {Will record the output into OutFile you specify}
OutFile: Text;
function Sum: integer;
var i,result : integer;
begin
result := 0;
For i := 1 to total Do
result := result + y[i];
Sum := result; {sum is the summation of 1's in y}
end;
begin
write('Enter Name of output File: ');
Readln(FileName);
Assign(OutFile,FileName+'.txt');
Rewrite(OutFile);
For sim := 1 to NumSim do {Do the simulation 5 times}
begin
Randomize;
for n := 1 to total do
y[n] := 0; {all people start out healthy (healthy - 0)}
y[5] := 1; {An infected person!}
for k := 1 to stages do
a[k,sim] := 0; {a[k,sim] is the number of infected people at stage k, simulation sim}
for k := 1 to stages do {begin simulation for each stage}
begin
for inner := 1 to count do {each person has count encounters per stage}
begin
for n := 1 to total do {individual n interacts with another person}
begin
m := trunc(total*Random) + 1;
if y[m] = 1 then {if individual m is infected}
if y[n] = 0 then {if individual n is not infected}
if random < tol then {if random number is less than tolerance}
y[n] := 1; {individual n is now infected!}
end; {loop on n}
end; {loop on inner}
a[k,sim] := sum; {sum the number of people infected at this stage}
end; {loop on k (stage)}
end; {loop on sim}
for i:= 1 to stages do
begin
for j := 1 to sim do
write(OutFile,a[i,j],',');
writeln(OutFile);
end;
Close(OutFile);
end.
Here's a text file of the population program.