function central2(p,n)
%CENTRAL2: Simulates a binomial random variable
%given its probability p and the number of
%trials n, then uses the simulation to 
%estimate p and determine confidence 
%intervals.
%
rng('shuffle')
X = round(rand([1,n])+(p-1/2));
%Estimator
pbar = sum(X)/n
%
format long
exacterror = abs(pbar-p)
error1 = 1/(2*sqrt(n)) %Using upper bound 1/4 on variance
error2 = sqrt((pbar-pbar^2)/n)  %Using biased variance estimator
error3 = sqrt(norm(X-pbar)^2/(n*(n-1))) %Using unbiased variance estimator
error4 = sqrt(var(X)/n) %Using MATLAB's built-in variance
