<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - comments on Post, Simulation of mean distance between random points in a hypercube</title>
    <link>http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Thu, 11 Jun 2026 11:51:45 GMT</lastBuildDate>
    <pubDate>Thu, 11 Jun 2026 11:51:45 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest comments added to the Post, Simulation of mean distance between random points in a hypercube</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - comments on Post, Simulation of mean distance between random points in a hypercube</title>
      <link>http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between</link>
    </image>
    <item>
      <title>Not linear</title>
      <link>http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between?ref=Feed:MaplePrimes:Simulation of mean distance between random points in a hypercube:Comments#comment123110</link>
      <itunes:summary>&lt;p&gt;Nice, but why the normal plots not linear ?&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, Simulation of mean distance between random points in a hypercube</description>
      <guid>123110</guid>
      <pubDate>Wed, 22 Jun 2011 21:00:52 Z</pubDate>
      <itunes:author>JoeKing</itunes:author>
      <author>JoeKing</author>
    </item>
    <item>
      <title>Normal Probability plots</title>
      <link>http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between?ref=Feed:MaplePrimes:Simulation of mean distance between random points in a hypercube:Comments#comment123116</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between#comment123110"&gt;@JoeKing&lt;/a&gt;, i assume you mean the normal probability plots ?&lt;/p&gt;
&lt;p&gt;Actually I think they are very good !&lt;br&gt;A&lt;span class="Apple-style-span" style="white-space: pre;"&gt;t first sight there appears to be a bit of a departure in the tails, but even when directly sampling a true &lt;br&gt;normal distribution, the points don't all lie exactly on the line at the tails, just due to random sampling. &lt;br&gt;To see this:&lt;/span&gt;&lt;/p&gt;
&lt;pre&gt;restart:&lt;br&gt;with(Statistics):&lt;br&gt;RV:=RandomVariable(Normal(0, 1)):&lt;br&gt;X:=Sample(RV,2000):&lt;br&gt;p1:=plot(PDF(RV,x),x=-4..4):&lt;br&gt;p2:=Histogram([X],bincount=15):&lt;br&gt;p1:=plots:-display(p1,p2):&lt;br&gt;p3:=ProbabilityPlot([X],Normal(0,1),thickness=2,color=BLACK):&lt;br&gt;plots:-display(Array([p1,p3]));&lt;/pre&gt;
&lt;pre&gt;&lt;a href="/view.aspx?sf=123116/388676/norm_0_1.png"&gt;&lt;img src="/view.aspx?sf=123116/388676/norm_0_1.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;First note that the bulk of the points lie very close the the line. As for the departures in the &lt;br&gt;tails, one important thing to check here is the scale of the y-axis. Note that the departures &lt;br&gt;in the vertical direction are quite small - even the largest is around 5% of the "true" value. &lt;br&gt;Now, looking at the normal probability plots in my original post above, the largest departure &lt;br&gt;is also of around 5%, while the bulk of the points are very close to the line.&lt;br&gt;&lt;br&gt;Now look at a sample taken from a skewed distribution.&lt;/pre&gt;
&lt;pre&gt;RV:=RandomVariable(Gamma(5,10)):&lt;br&gt;p1:=plot(PDF(RV,x),x=0..150):&lt;br&gt;X:=Sample(RV,1000):&lt;br&gt;p2:=Histogram([X],bincount=15):&lt;br&gt;p1:=plots:-display(p1,p2):&lt;br&gt;p3:=ProbabilityPlot([X],Normal(50,sqrt(250)),thickness=2,color=BLACK):&lt;br&gt;plots:-display(Array([p1,p3]));&lt;/pre&gt;
&lt;pre&gt;&lt;a href="/view.aspx?sf=123116/388682/gamma_5_10.png"&gt;&lt;img src="/view.aspx?sf=123116/388682/gamma_5_10.png" alt=""&gt;&lt;/a&gt;&lt;br&gt;&lt;br&gt;First note (from the pdf plot) that this distribution is not *greatly* skewed, but the normal &lt;br&gt;probability plot clearly shows two things. First the points themselves show a systematic&lt;br&gt;curvature throughout the whole range; and second, the largest departures are &lt;br&gt;100%+ at the left side and 20%+ on the right.  You don't see features like this in the plots&lt;br&gt;I posted above.&lt;br&gt;&lt;br&gt;&lt;/pre&gt;
&lt;pre&gt;&amp;nbsp;Edit: Add histogram to pdf plot&lt;/pre&gt;
&lt;pre&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, Simulation of mean distance between random points in a hypercube</description>
      <guid>123116</guid>
      <pubDate>Wed, 22 Jun 2011 23:12:52 Z</pubDate>
      <itunes:author>longrob</itunes:author>
      <author>longrob</author>
    </item>
    <item>
      <title>Nice</title>
      <link>http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between?ref=Feed:MaplePrimes:Simulation of mean distance between random points in a hypercube:Comments#comment123887</link>
      <itunes:summary>&lt;p&gt;Nice work, longrob. By the way, here is a neat (I think) trick to make ncubem even faster. The &lt;em&gt;Statistics:-Sample&lt;/em&gt;&amp;nbsp;command can sample complicated algebraic expressions involving random variables; all of this is done in external code and therefore lightning fast. So we can do (version 2) :&lt;/p&gt;
&lt;pre&gt;ncubem2 := proc(n :: posint, N :: posint, m)&lt;br&gt;uses&lt;br&gt;    S = Statistics;&lt;br&gt;local&lt;br&gt;    expr,&lt;br&gt;    i,&lt;br&gt;    variables;&lt;br&gt;    &lt;br&gt;    variables := [seq(S:-RandomVariable('Uniform'(0, m)), i = 1 .. 2*n)];&lt;br&gt;    expr := sqrt(add((variables[2*i-1] - variables[2*i])^2, i = 1 .. n));&lt;br&gt;    return S:-Mean(S:-Sample(expr, N));&lt;br&gt;end proc;&lt;/pre&gt;
&lt;p&gt;If we do this, on my home machine I get:&lt;/p&gt;
&lt;pre&gt;CodeTools:-Usage(ncubem(15, 1000, 1), iterations=100):&lt;br&gt;memory used=14.18MiB, alloc change=32.12MiB, cpu time=171.05ms, real time=173.70ms&lt;br&gt;CodeTools:-Usage(ncubem2(15, 1000, 1), iterations=100):&lt;br&gt;memory used=0.60MiB, alloc change=0 bytes, cpu time=13.76ms, real time=13.86ms&lt;/pre&gt;
&lt;p&gt;Further examination shows that about 1/3 of the time is spent generating the random variables (30 per call, in this example) and 1/3 of the time is spent computing the symbolic square root in &lt;em&gt;expr&lt;/em&gt;, which returns unevaluated. This leads to the following optimization (version 3) :&lt;/p&gt;
&lt;pre&gt;ncubem3 := module()&lt;br&gt;local variableStorage, getVariables, ModuleApply;&lt;br&gt;    variableStorage := Vector(0);&lt;br&gt;&lt;br&gt;    # Return at least k uniform(0, 1) random variables.&lt;br&gt;    getVariables := proc(k)&lt;br&gt;    local&lt;br&gt;        i;&lt;br&gt;        if numelems(variableStorage) &amp;lt; k then&lt;br&gt;            for i from numelems(variableStorage) + 1 to k do&lt;br&gt;                variableStorage(i) := Statistics:-RandomVariable('Uniform(0, 1)');&lt;br&gt;            end do;&lt;br&gt;        end if;&lt;br&gt;&lt;br&gt;        return variableStorage;&lt;br&gt;    end proc;&lt;br&gt;&lt;br&gt;    ModuleApply :=  proc(n :: posint, N :: posint, m)&lt;br&gt;    local&lt;br&gt;        expr,&lt;br&gt;        i,&lt;br&gt;        variables;&lt;br&gt;&lt;br&gt;        variables := getVariables(2 * n);&lt;br&gt;        expr := 'sqrt'(add((variables[2*i-1] - variables[2*i])^2, i = 1 .. n));&lt;br&gt;        return S:-Mean(S:-Sample(expr, N));&lt;br&gt;    end proc;&lt;br&gt;end module;&lt;br&gt;CodeTools:-Usage(ncubem3(15, 1000, 1), iterations=100):&lt;br&gt;memory used=360.52KiB, alloc change=0 bytes, cpu time=7.00ms, real time=7.06ms&lt;/pre&gt;
&lt;p&gt;A total speedup of about a factor 25.&lt;/p&gt;
&lt;p&gt;Hope this helps,&lt;/p&gt;
&lt;p&gt;Erik Postma&amp;nbsp;&lt;br&gt;Maplesoft.&amp;nbsp;&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, Simulation of mean distance between random points in a hypercube</description>
      <guid>123887</guid>
      <pubDate>Fri, 15 Jul 2011 09:42:20 Z</pubDate>
      <itunes:author>epostma</itunes:author>
      <author>epostma</author>
    </item>
    <item>
      <title>@epostma&amp;nbsp;thank you very much for your</title>
      <link>http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between?ref=Feed:MaplePrimes:Simulation of mean distance between random points in a hypercube:Comments#comment123890</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between#comment123887"&gt;@epostma&lt;/a&gt;&amp;nbsp;thank you very much for your comments and the improved code. That's a terrific efficiency gain :-)&lt;/p&gt;
&lt;p&gt;I didn't really understand version 3. Can you enlighten me ? And why is it so much faster that version 2 ?&lt;/p&gt;
&lt;p&gt;I have another question: how do you determine the time spent in different parts of the procedure ?&lt;/p&gt;
&lt;p&gt;And just a trivial point: &amp;nbsp;You seem to have left out&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;uses&lt;/span&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt; S = Statistics;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;from version 3 : I guess you had S declared at the global level in your worksheet ?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;Thanks again&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;LR&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span class="Apple-style-span" style="white-space: pre;"&gt;&lt;br&gt;&lt;/span&gt;&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, Simulation of mean distance between random points in a hypercube</description>
      <guid>123890</guid>
      <pubDate>Fri, 15 Jul 2011 14:17:27 Z</pubDate>
      <itunes:author>longrob</itunes:author>
      <author>longrob</author>
    </item>
    <item>
      <title>Answers - and a fourth version</title>
      <link>http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between?ref=Feed:MaplePrimes:Simulation of mean distance between random points in a hypercube:Comments#comment123895</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between#comment123890"&gt;@longrob&lt;/a&gt; : I'll answer your questions in random order.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Determining the time spent in different parts of a program is called profiling, and in Maple this functionality is provided by the&amp;nbsp; &lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=CodeTools/Profiling"&gt;CodeTools:-Profiling&lt;/a&gt;&amp;nbsp; package - in particular, the&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=CodeTools/Profiling/Profile"&gt;CodeTools:-Profiling:-Profile&lt;/a&gt; and&amp;nbsp;&lt;a href="http://www.maplesoft.com/support/help/view.aspx?path=showstat"&gt;showstat&lt;/a&gt; commands. I think the help pages probably have enough detail to get you started (now that you know where to look! :) ).&lt;/li&gt;
&lt;li&gt;The difference between versions 2 and 3 are twofold: first of all, the RandomVariables are created only once (creating such a random variable is not a big computation, but the administrative overhead is substantial) and then remembered. This is accomplished in the variableStorage Vector and the getVariables procedure. Secondly, using the profiling mentioned in the previous bullet point, I saw that the line defining &lt;em&gt;expr&lt;/em&gt; also took substantial time. This could really only come from the &lt;em&gt;sqrt&lt;/em&gt; function call. By enclosing &lt;em&gt;sqrt&lt;/em&gt; in forward quotes, I prevented Maple from doing any actual computation there; when the expression enters &lt;em&gt;Sample&lt;/em&gt;, and via that enters the external code, all computation happens there anyway.&lt;/li&gt;
&lt;li&gt;I think leaving out &lt;em&gt;uses S = Statistics;&lt;/em&gt; was simply a copy and paste error - I'm pretty sure I had it in my original version 3 code as well. But it doesn't matter - thanks for catching it!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, I realized late last night that part of the evaluation in the external C code still happens inside Maple - the external code calls back into the interpreted Maple environment to evaluate part of the expressions. So I came up with the following:&lt;/p&gt;
&lt;pre&gt;ncubem4 := module()&lt;br&gt;local&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ModuleApply, normalSample, sampleStorage, processor;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; normalSample := Statistics:-Sample('Uniform(0, 1)');&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; sampleStorage := Vector(0, 'datatype = float');&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; processor := proc(s :: Vector(datatype = float[8]),&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; n :: integer,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; N :: integer)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; local&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i :: integer,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intermediate :: float[8],&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; j :: integer,&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result :: float[8];&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result := 0.;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for i to 2*n*N by 2*n do&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intermediate := 0.;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for j from i to i + 2*n - 1 by 2 do&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; intermediate := intermediate + (s[j] - s[j+1])^2;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end do;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; result := result + sqrt(intermediate);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end do;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return result / N;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end proc;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; processor := Compiler:-Compile(processor);&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ModuleApply := proc(n :: posint, N :: posint, m)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if numelems(sampleStorage) &amp;lt; 2*n*N then&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Sample storage is too small to contain sufficiently many&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # sampled numbers: allocate a new Vector.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sampleStorage := normalSample(2*n*N);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; elif numelems(sampleStorage) &amp;gt; 2*n*N then&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Sample storage is bigger than needed - fill only an&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # initial segment.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; normalSample(ArrayTools:-Alias(sampleStorage, [2*n*N]));&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # Sample storage is exactly the right size - fill it up&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; # with fresh samples.&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; normalSample(sampleStorage);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end if;&lt;br&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return m * processor(sampleStorage, n, N);&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end proc;&lt;br&gt;end module;&lt;br&gt;CodeTools:-Usage(ncubem4(15, 1000, 1), iterations=1000):&lt;br&gt;memory used=1.20KiB, alloc change=0.75MiB, cpu time=2.30ms, real time=2.31ms&lt;/pre&gt;
&lt;p&gt;One caveat is that this will only work in hardware float mode; if you set Digits higher than evalhf(Digits) (which is currently 15 on all platforms) or you set UseHardwareFloats to false, the code will die miserably. However, this is stuff you shouldn't do with high precision anyway: the Monte Carlo scheme destroys the high precision anyway.&lt;/p&gt;
&lt;p&gt;The numbers here are a bit skewed since this is my work machine instead of home - the numbers I get here for the other versions are: 200.64ms for ncubem, 31.55ms for ncubem2, 7.10ms for ncubem3. So here we have another factor of 3 over ncubem3.&lt;/p&gt;
&lt;p&gt;Erik.&lt;/p&gt;</itunes:summary>
      <description>The latest comments added to the Post, Simulation of mean distance between random points in a hypercube</description>
      <guid>123895</guid>
      <pubDate>Fri, 15 Jul 2011 18:32:11 Z</pubDate>
      <itunes:author>epostma</itunes:author>
      <author>epostma</author>
    </item>
    <item>
      <title>@epostma&amp;nbsp;
Thanks again. But in version</title>
      <link>http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between?ref=Feed:MaplePrimes:Simulation of mean distance between random points in a hypercube:Comments#comment123909</link>
      <itunes:summary>&lt;p&gt;&lt;a href="http://www.mapleprimes.com/posts/123103-Simulation-Of-Mean-Distance-Between#comment123895"&gt;@epostma&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks again. But in version 4 I get the following error:&lt;/p&gt;
&lt;pre&gt;Error, (in Compiler:-Compile) compiler exited with nonzero status 1: &lt;/pre&gt;</itunes:summary>
      <description>The latest comments added to the Post, Simulation of mean distance between random points in a hypercube</description>
      <guid>123909</guid>
      <pubDate>Sun, 17 Jul 2011 13:23:46 Z</pubDate>
      <itunes:author>longrob</itunes:author>
      <author>longrob</author>
    </item>
  </channel>
</rss>