Question: Make my procedure lightning fast

The procedure p gives an approximation for Pi. Idea is to place a unit circle in a unit square, throw in some random points (which eventually will be plotted into this figure) and count the points inside the circle. For large n, the quotient n_circle/n_square should tend to Pi/4. But for large n, there may be faster ways to program this, what would you improve ? But keep the principle of this algorithm as it is.  I'd love to have at least 200k points, but this takes annoying 25s on my machine on each run.

 

with(RandomTools):with(Statistics):
p:=proc(N) # N number of points
local F,X,Y,m,m2,f,n,inner,P;
n:=N;
F:=RandomVariable(Uniform(-1/2, 1/2));
X:=Sample(F,n);
Y:=Sample(F,n);
P:=zip((x, y)->[x, y],X,Y);
m:=seq(sqrt(i[1]^2+i[2]^2), `in`(i, P));
m2:=map(evalb@(x->x>1/2),[m]);
inner:=numboccur(false,m2);
evalf(4*inner/nops([m]));
end proc;

CodeTools[Usage](p(50000));

Please Wait...