Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Re: Random numbers for C: End, at last?
Posted:
Nov 29, 2004 6:54 PM
|
|
I wrote: >> Looking at the code in Marsaglia's post at <a href="http://tinyurl.com/4etu9,">http://tinyurl.com/4etu9,</a> I can >> see a few places where a 32-bit word was implicitly required: SHR3, CONG, >> FIB, LFIB4, and SWB. So yes, if you want those to behave as if they were on >> a 32-bit machine, you'll need to insert appropriate AND-masking to make it >> so.
and DZ replied: > I'm going with an easy but non-portable solution that works with GNU > g++/gcc. Is explicit AND-masking more efficient? Replace > > typedef unsigned long UL; > > in <a href="http://tinyurl.com/4etu9">http://tinyurl.com/4etu9</a> with > > #include <stdint.h> > 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
|
|
|
|