Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » sci.math.* » sci.math

Topic: Random numbers for C: End, at last?
Replies: 6   Last Post: Nov 29, 2004 6:54 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bob Harris

Posts: 54
Registered: 12/13/04
Re: Random numbers for C: End, at last?
Posted: Nov 29, 2004 6:54 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


I wrote:
&gt;&gt; Looking at the code in Marsaglia's post at <a href="http://tinyurl.com/4etu9,">http://tinyurl.com/4etu9,</a> I can
&gt;&gt; see a few places where a 32-bit word was implicitly required: SHR3, CONG,
&gt;&gt; FIB, LFIB4, and SWB. So yes, if you want those to behave as if they were on
&gt;&gt; a 32-bit machine, you'll need to insert appropriate AND-masking to make it
&gt;&gt; so.

and DZ replied:
&gt; I'm going with an easy but non-portable solution that works with GNU
&gt; g++/gcc. Is explicit AND-masking more efficient? Replace
&gt;
&gt; typedef unsigned long UL;
&gt;
&gt; in <a href="http://tinyurl.com/4etu9">http://tinyurl.com/4etu9</a> with
&gt;
&gt; #include &lt;stdint.h&gt;
&gt; typedef uint32_t UL;

That looks like an excellent solution to me! I believe the compiler will do
a better job of figuring out how to accomplish the task than if you
explicitly added the masking.

Bob H




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.