<rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0">
  <channel>
    <title>MaplePrimes - comments on Post, Generating an Array of Random Floats</title>
    <link>http://www.mapleprimes.com/posts/41873-Generating-An-Array-Of-Random-Floats</link>
    <language>en-us</language>
    <copyright>2026 Maplesoft, A Division of Waterloo Maple Inc.</copyright>
    <generator>Maplesoft Document System</generator>
    <lastBuildDate>Tue, 09 Jun 2026 09:27:47 GMT</lastBuildDate>
    <pubDate>Tue, 09 Jun 2026 09:27:47 GMT</pubDate>
    <itunes:subtitle />
    <itunes:summary />
    <description>The latest comments added to the Post, Generating an Array of Random Floats</description>
    <image>
      <url>http://www.mapleprimes.com/images/mapleprimeswhite.jpg</url>
      <title>MaplePrimes - comments on Post, Generating an Array of Random Floats</title>
      <link>http://www.mapleprimes.com/posts/41873-Generating-An-Array-Of-Random-Floats</link>
    </image>
    <item>
      <title>You can go even faster, if you don't mind cheating a little</title>
      <link>http://www.mapleprimes.com/posts/41873-Generating-An-Array-Of-Random-Floats?ref=Feed:MaplePrimes:Generating an Array of Random Floats:Comments#comment78220</link>
      <itunes:summary>&lt;pre&gt;
proc(n::posint) local t;
uses RandomTools; kernelopts(opaquemodules=false):
t := (a,b) -&gt; MersenneTwister:-MTKernelInterface(3);
  Array(1..n, 1..2
        , t 
        , 'datatype'=float[8] 
       );
end proc&lt;/pre&gt;
beats your picks[1.0] (on my computer anyways).

Two tricks here: one is to avoid the intermediate data-structure (the list) altogether, the other is to do very aggressive manual inlining.  I took a look at what was, in the end, actually executed, and used just that.

I don't know of a way to eliminate both the intermediate data-structure and the intermediate function at the same time.</itunes:summary>
      <description>The latest comments added to the Post, Generating an Array of Random Floats</description>
      <guid>78220</guid>
      <pubDate>Mon, 12 Feb 2007 05:51:15 Z</pubDate>
      <itunes:author>JacquesC</itunes:author>
      <author>JacquesC</author>
    </item>
    <item>
      <title>rtable</title>
      <link>http://www.mapleprimes.com/posts/41873-Generating-An-Array-Of-Random-Floats?ref=Feed:MaplePrimes:Generating an Array of Random Floats:Comments#comment78218</link>
      <itunes:summary>Does this serve?

proc(n::posint)
rtable(1..n,1..2,frandom(0.0,1.0),subtype=Array,datatype=float[8]);
end proc:

acer</itunes:summary>
      <description>The latest comments added to the Post, Generating an Array of Random Floats</description>
      <guid>78218</guid>
      <pubDate>Mon, 12 Feb 2007 06:20:07 Z</pubDate>
      <itunes:author>acer</itunes:author>
      <author>acer</author>
    </item>
    <item>
      <title>frandom</title>
      <link>http://www.mapleprimes.com/posts/41873-Generating-An-Array-Of-Random-Floats?ref=Feed:MaplePrimes:Generating an Array of Random Floats:Comments#comment78217</link>
      <itunes:summary>Nice suggestion, Acer. I didn't know about the frandom option to rtable.  It isn't clear from the rtable help page precisely what it does (no mention whether the numbers are uniformly generated). Also, its first argument is supposed to be a range, but giving it just a 0.0, as you did, seems to work.  It is significantly faster (orders of magnitude) than the other approaches.  I'll update the main blog entry with this and Jacques' suggestion.</itunes:summary>
      <description>The latest comments added to the Post, Generating an Array of Random Floats</description>
      <guid>78217</guid>
      <pubDate>Mon, 12 Feb 2007 07:01:33 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>Fully compiled vs interpreted</title>
      <link>http://www.mapleprimes.com/posts/41873-Generating-An-Array-Of-Random-Floats?ref=Feed:MaplePrimes:Generating an Array of Random Floats:Comments#comment78208</link>
      <itunes:summary>Acer's suggestion is very sweet indeed.  You should probably move up to n=5*10^6 or even higher to really show that off.  That would also show how memory use makes some of the other solutions degrade even more in comparison.

And the difference in times between all of these is all about interpretation overhead:  picks[4] is essentially all interpreter-bound (a high printlevel output makes that very clear), with the additional drawback of needing a lot of memory.  Most improvements after that work on peeling back the pieces of the interpreter until very little is needed.  picks[0.65] shows how far (with tricks) one can go.  I did not know about the map trick [ie that map on an empty array was that much faster than all other methods of initializing things; this clearly points to an area where rtable can still be optimized!].  Very nice.  But then one sees what happens when 100% of the computation is done in the kernel, with essentially no interpreter overhead: blinding speed!

picks[4] is not an unnatural piece of code at all - and yet it is 4 orders (of 10) magnitude slower than the 'best' solution.  No wonder a lot of people out there have an impression that Maple is slow [it's not, but there are probably less than 20 people in the world who can make Maple go "fast enough", and not enough of those are not somehow employed by Maplesoft!].

</itunes:summary>
      <description>The latest comments added to the Post, Generating an Array of Random Floats</description>
      <guid>78208</guid>
      <pubDate>Mon, 12 Feb 2007 21:00:16 Z</pubDate>
      <itunes:author>JacquesC</itunes:author>
      <author>JacquesC</author>
    </item>
    <item>
      <title>hardware floats</title>
      <link>http://www.mapleprimes.com/posts/41873-Generating-An-Array-Of-Random-Floats?ref=Feed:MaplePrimes:Generating an Array of Random Floats:Comments#comment85932</link>
      <itunes:summary>Note that essentially all the performance gain of picks[0.1] is achieved when the &lt;b&gt;datatype=float[8]&lt;/b&gt; option is provided.  Without it, picks[0.1] runs at the same speed as picks[0.65] (the map trick with unevaluated rnd(3)).   

While trying other improvements I stumbled across this "gem"&lt;pre&gt;
picks[0] := proc(n::posint)
local opacity,rnd;
    opacity := kernelopts('opaquemodules'=false);
    rnd := RandomTools:-MersenneTwister:-MTKernelInterface;
    kernelopts('opaquemodules'=opacity);
    eval(Array(1..n,1..2,'fill=rnd(3)'));
end proc:&lt;/pre&gt;It was four times faster than picks[0.1]!  Then I discovered a tragic flow:&lt;pre&gt; A := picks[0](2);
                   [0.849129305868777108    0.678735154857773470]
              A := [                                            ]
                   [0.743132468124916179    0.655477890177556644]

A[1,1] &amp;lt;&amp;gt; A[1,1];
                  0.171186687811561766 &amp;lt;&amp;gt; 0.706046088019608775&lt;/pre&gt;It's clear now what the problem is, but I found it amusing.
</itunes:summary>
      <description>The latest comments added to the Post, Generating an Array of Random Floats</description>
      <guid>85932</guid>
      <pubDate>Mon, 12 Feb 2007 21:21:55 Z</pubDate>
      <itunes:author>Joe
 Riel
</itunes:author>
      <author>Joe
 Riel
</author>
    </item>
    <item>
      <title>Clear to very few</title>
      <link>http://www.mapleprimes.com/posts/41873-Generating-An-Array-Of-Random-Floats?ref=Feed:MaplePrimes:Generating an Array of Random Floats:Comments#comment91160</link>
      <itunes:summary>I wonder how many people could actually puzzle out what is going on with that above?  It involves a lot of rather complex knowledge of Maple.  It would make a good test question for a &lt;a href="http://www.mapleprimes.com/book/maple-401"&gt;maple 401&lt;/a&gt; test!</itunes:summary>
      <description>The latest comments added to the Post, Generating an Array of Random Floats</description>
      <guid>91160</guid>
      <pubDate>Mon, 12 Feb 2007 21:58:01 Z</pubDate>
      <itunes:author>JacquesC</itunes:author>
      <author>JacquesC</author>
    </item>
  </channel>
</rss>