# How to choose the number of random points in Monte Carlo simulations?

I am struggling with convergence criteria when performing a Monte carlo simulation on a uniform distribution. Any help would be much appreciated !

Say I want to sample uniformly a 1D interval (for the sake of simplicity).

I use a random number generator (in Fortran) to draw X values between 0 and 1. Then, how do i choose the number of points N such that I have a good sampling?

I know the expected mean ( = 0.5) and I can easily compute the average of the positions of my MC points, i.e. μ = (X_1 +... + X_N) / N. I was thinking that I could define a simple criterion such that: μ / < 1% for instance, in order to decide if N is large enough or not...

Please can anyone tell me if there is a better way to figure this out?

Thanks a lot !

• Point of interest: This question is answered many times in many variations at CV.SE. – Sycorax Nov 18 '15 at 19:26
• @user777: Please provide at least one link for reference. I'm sure the OP will appreciate it. – Paul Nov 18 '15 at 20:26
• – Sycorax Nov 18 '15 at 20:29

Monte Carlo converges at a rate $O(\frac{1}{\sqrt{N}})$, where $N$ is the sample size. This means the absolute error is bounded as $|\mu-\mu_{approx}|<\frac{C}{\sqrt{N}}$, where C is some constant. Roughly speaking, this means for every additional digit of accuracy, you will need 100 times more points. Since you need two digits of accuracy to obtain 1% accuracy (i.e. because 1% is equivalent to 0.01), you will somewhere on the order of $100*100=10^5$ points. This estimate is not a guarantee that you will obtain 1% accuracy with exactly $10^5$ points because we don't know the constant C. This constant depends on the properties of the function you are sampling and its order of magnitude may not be estimatable.
Typically, a good way would be to estimate the variance of simulation with each sample size, $n$, as $\sigma^2_n$. Then the standard error for $n$ samples would be $\frac{\sigma_n}{\sqrt{n}}$. You could repeat the error estimates by increasing your sample size and stop at that sample size for which the error hits a certain threshold.