Rand does not return expected confidence interval

Dear all,
Testing Rand() on MC algorithm for estimating integral of Sine from 0 to Pi,
only returns 50% of the expected confidence interval.
Can anybody see, where my code breaks?

n = 1000
in_ci = 0
for i in 1:500
sin_arr = map(x → sin(x), pirand(n))
lower = pi
mean(sin_arr) - 1.96std(sin_arr)/sqrt(n)
upper = pi
mean(sin_arr) + 1.96*std(sin_arr)/sqrt(n)
if (lower <= 2) && (upper >= 2)
in_ci += 1
end
end
println("For n = ", n, " share of estimates in CI.: ", in_ci/500)

Result.:
For n = 1000 share of estimates in CI.: 0.468

Welcome to the forum! Note that you can wrap your code in triple backticks (`) to properly quote your code.

I think you will get the correct result if you also multiply your standard error by pi?

Thx, got blind staring at the code :slight_smile: