program assignment3_3a;

uses crt, math;

var threshold, n, mean, sum, sigma:real;
    i, j, trials, samplesize, count:longint;

begin

  Randomize;

  threshold:=0.01;

  writeln('What should the nominal count rate be?');
  readln(n);

  writeln();
  writeln('How many trials should be simulated?');
  readln(trials);

  samplesize:=round(n/threshold);

  writeln(' Trial | Count ');
  writeln('-------+-------');

  for i:=1 to trials do begin

    count:=0;

    for j:=1 to samplesize do begin
      if Random<threshold then count:=count+1;
    end;

    writeln(i:6,' |',count:6);

    mean:=mean+count;
    sum:=sum+sqr(count);

  end;

  mean:=mean/trials;

  sigma:=sqrt(sum/trials - sqr(mean));

  writeln();
  writeln('mean = ',mean:8:4);
  writeln('s.d. = ',sigma:8:4);

  writeln();
  write('Press any key to continue.');
  readln;

end.