I have the following functions:
T = Compile[{n}, Boole[Sum[RandomReal[]^2, {n}] <= 1]];
Monte[d_, n_] := Sum[T[d], {n}]/n*2^d
T is a function that generates a random n-dimensional point in the n-dimensional unit hypercube and determines if it is within the n-dimensional unit hypersphere. Monte is a function that samples $n$ such points in $d$-dimenional space. For "small" numbers of points, Monte works fine:
Monte[2, 10^4]*1.0
(* 3.1244 *)
Please note that every time Monte is run the output will be different when Monte is working correctly, so the above output is just one of a number of possible outputs. Anyway: Monte breaks when I try inputting a larger value for $n$:
Monte[2, 10^7]*1.0
(* 4.*10^-7 Sum[1, {10000000}] *)
Why does this occur?
Edit: I tested it when T is declared as a regular function and not a compiled function:
T = Boole[Sum[RandomReal[]^2, {#}] <= 1] &;
Monte[d_, n_] := Sum[T[d], {n}]/n*2^d;
Monte[2, 10^7]*1.0
(* 4.*10^-7 Sum[1, {10000000}] *)