sum=0; for i=1:N x=-1+2*rand(); y=-1+2*rand(); if (x^2+y^2<1) sum=sum+1; end end p=sum/N*4