I was playing around with writing a code for Montecarlo integration of a function defined in spherical coordinates. As a first simple rapid test I decided to write a test code to obtain the solid angle under an angle $\theta_m$. For two random number $u$ and $v$ in $[0,1)$. I generate an homogeneous random sampling of the spherical angle using $\phi=2\pi u$ and $\theta =\arccos(1-2v)$.
For N generated points, I have M points for which $\theta < \theta_m$. My first idea was that since I have an homogeneous sampling I should have obtained the correct solid angle $\Omega=2 \pi (1-\cos (\theta_m))$ simply as $4\pi\times \frac{M}{N}$. Actually it looks like I the correct result comes out only if I use:
$\Omega=\sum_{i=1}^M \frac{4\pi}{N} 2 cos(\theta_i)$
I can not see the reason why this should be correct. The probability distribution function in $\theta$ is $PDF=\frac{1}{2} \sin(\theta)$ so I would rather expect I should normalize each point of the sum by this function but this doesn't works. What am I doing wrong and how could I justify the cosinus? Many thanks!