Author 
Message 
os2_user@hotmail.com science forum beginner
Joined: 14 Nov 2005
Posts: 9

Posted: Mon Nov 14, 2005 5:56 am Post subject:
Double precision random number generator in Fortran 77



What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
Thanks. 

Back to top 


George Marsaglia science forum beginner
Joined: 24 May 2005
Posts: 21

Posted: Mon Nov 14, 2005 11:57 am Post subject:
Re: Double precision random number generator in Fortran 77



<os2_user@hotmail.com> wrote in message
news:1131947785.377811.265640@o13g2000cwo.googlegroups.com...
Quote:  What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?

The article
"The 64bit universal RNG", (2004)
{\it Statistics and Probability Letters}, {\bf 66}, no. 2, 183187,
(with Wai Wan Tsang)
describes a method for producing an IEEE standard double precision
uniform [0,1) random variable.
It is simple, fast, and seems to pass tests of randomness very well.
Based on a method I developed for use in Matlab, the 32bit
floating point version was described in
"Toward a Universal Random Number Generator,''
Statistics and Probability Letters \bf 8, \rm No. 5, 1989
I can send my .ps or .pdf versions for those who have
trouble accessing those articles.
George Marsaglia
geo@stat.fsu.edu 

Back to top 


os2_user@hotmail.com science forum beginner
Joined: 14 Nov 2005
Posts: 9

Posted: Tue Nov 15, 2005 1:36 am Post subject:
Re: Double precision random number generator in Fortran 77



Thanks for the reply. Is the code available for downloading on the web?
I haver't seen your paper so I don't know if it's listed there. How do
you compare it to DUNI and Ranlux, since these are both based on your
work?
Thanks. 

Back to top 


Phillip Helbigremove C science forum addict
Joined: 06 May 2005
Posts: 88

Posted: Tue Nov 15, 2005 8:12 am Post subject:
Re: Double precision random number generator in Fortran 77



In article <1131947785.377811.265640@o13g2000cwo.googlegroups.com>,
os2_user@hotmail.com writes:
Quote:  What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?

If you use RANLUX on the highest luxury level, then "all 24 bits are
chaotic". So, you can do something you normally never should do with
RNGs, namely construct your doubleprecision mantissa from bits obtained
by more than one call to RANLUX. (Of course, RANLUX can give you a
vector with one call, so you could just use that.) 

Back to top 


os2_user@hotmail.com science forum beginner
Joined: 14 Nov 2005
Posts: 9

Posted: Tue Nov 15, 2005 10:56 am Post subject:
Re: Double precision random number generator in Fortran 77



Phillip Helbigremove CLOTHES to reply wrote:
Quote:  In article <1131947785.377811.265640@o13g2000cwo.googlegroups.com>,
os2_user@hotmail.com writes:
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
If you use RANLUX on the highest luxury level, then "all 24 bits are
chaotic". So, you can do something you normally never should do with
RNGs, namely construct your doubleprecision mantissa from bits obtained
by more than one call to RANLUX. (Of course, RANLUX can give you a
vector with one call, so you could just use that.)

Is it bad just to change everything in Ranlux from real to double
precision with an implicit double precision statement at the start? I
did find a version that did just that. I guess the first few numbers
may not be random to 16 digits but would things be ok once the
generator "warms up"?
Thanks. 

Back to top 


Everett M. Greene science forum beginner
Joined: 09 Aug 2005
Posts: 32

Posted: Tue Nov 15, 2005 6:09 pm Post subject:
Re: Double precision random number generator in Fortran 77



helbig@astro.multiCLOTHESvax.de (Phillip Helbig) writes:
Quote:  os2_user@hotmail.com writes:
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
If you use RANLUX on the highest luxury level, then "all 24 bits are
chaotic". So, you can do something you normally never should do with
RNGs, namely construct your doubleprecision mantissa from bits obtained
by more than one call to RANLUX. (Of course, RANLUX can give you a
vector with one call, so you could just use that.)

??? "all 24 bits"? There are 52 bits in an IEEE
doubleprecision float mantissa. 

Back to top 


Hugo Pfoertner science forum addict
Joined: 02 May 2005
Posts: 51

Posted: Tue Nov 15, 2005 7:30 pm Post subject:
Re: Double precision random number generator in Fortran 77



os2_user@hotmail.com wrote:
Quote: 
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
Thanks.

Links to several implementations of the Mersenne Twister PRNG written in
Fortran can be found at
http://www.math.sci.hiroshimau.ac.jp/~mmat/MT/VERSIONS/FORTRAN/fortran.html
Since the use of nonstandard shift and bitwise logical functions in
these version might be problematic on some systems I would recommend to
use the original version of the MT (written in C)
http://www.math.sci.hiroshimau.ac.jp/~mmat/MT/VERSIONS/CLANG/clang.html
and link it to your Fortran code.
Hugo Pfoertner 

Back to top 


N. Shamsundar science forum beginner
Joined: 10 Oct 2005
Posts: 40

Posted: Wed Nov 16, 2005 12:25 pm Post subject:
Re: Double precision random number generator in Fortran 77



Everett M. Greene wrote:
Quote:  helbig@astro.multiCLOTHESvax.de (Phillip Helbig) writes:
os2_user@hotmail.com writes:
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
If you use RANLUX on the highest luxury level, then "all 24 bits are
chaotic". So, you can do something you normally never should do with
RNGs, namely construct your doubleprecision mantissa from bits obtained
by more than one call to RANLUX. (Of course, RANLUX can give you a
vector with one call, so you could just use that.)
??? "all 24 bits"? There are 52 bits in an IEEE
doubleprecision float mantissa.
What he said was equivalent to "take as many 24 bit scalar or vector 
elements as are needed to fill your nnbit mantissa". The "all" applied
to all the bits of the basic 24bit integer RN from the RANLUX algorithm.
N. Shamsundar
University of Houston 

Back to top 


os2_user@hotmail.com science forum beginner
Joined: 14 Nov 2005
Posts: 9

Posted: Thu Nov 17, 2005 2:44 am Post subject:
Re: Double precision random number generator in Fortran 77



Hugo Pfoertner wrote:
Quote:  os2_user@hotmail.com wrote:
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
Thanks.
Links to several implementations of the Mersenne Twister PRNG written in
Fortran can be found at
http://www.math.sci.hiroshimau.ac.jp/~mmat/MT/VERSIONS/FORTRAN/fortran.html

The Fortran 77 version doesn't compile. There is an illegal data
statement for the variable mti which is in COMMON. It can be fixed by
having a block data statement. Has anyone else noticed this error? 

Back to top 


Paul Victor Birke science forum beginner
Joined: 01 May 2005
Posts: 10

Posted: Thu Nov 17, 2005 4:00 am Post subject:
Re: Double precision random number generator in Fortran 77



it compiles and runs under watcom
os2_user@hotmail.com wrote:
Quote:  Hugo Pfoertner wrote:
os2_user@hotmail.com wrote:
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
Thanks.
Links to several implementations of the Mersenne Twister PRNG written in
Fortran can be found at
http://www.math.sci.hiroshimau.ac.jp/~mmat/MT/VERSIONS/FORTRAN/fortran.html
The Fortran 77 version doesn't compile. There is an illegal data
statement for the variable mti which is in COMMON. It can be fixed by
having a block data statement. Has anyone else noticed this error?



Back to top 


os2_user@hotmail.com science forum beginner
Joined: 14 Nov 2005
Posts: 9

Posted: Thu Nov 17, 2005 10:51 am Post subject:
Re: Double precision random number generator in Fortran 77



paul v birke wrote:
Quote:  it compiles and runs under watcom

That's strange. Lahey doesn't like it and my Fortran book says it's an
error.
Quote: 
os2_user@hotmail.com wrote:
Hugo Pfoertner wrote:
os2_user@hotmail.com wrote:
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
Thanks.
Links to several implementations of the Mersenne Twister PRNG written in
Fortran can be found at
http://www.math.sci.hiroshimau.ac.jp/~mmat/MT/VERSIONS/FORTRAN/fortran.html
The Fortran 77 version doesn't compile. There is an illegal data
statement for the variable mti which is in COMMON. It can be fixed by
having a block data statement. Has anyone else noticed this error?



Back to top 


os2_user@hotmail.com science forum beginner
Joined: 14 Nov 2005
Posts: 9

Posted: Thu Nov 17, 2005 12:39 pm Post subject:
Re: Double precision random number generator in Fortran 77



George Marsaglia wrote:
Quote:  os2_user@hotmail.com> wrote in message
news:1131947785.377811.265640@o13g2000cwo.googlegroups.com...
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
The article
"The 64bit universal RNG", (2004)
{\it Statistics and Probability Letters}, {\bf 66}, no. 2, 183187,
(with Wai Wan Tsang)
describes a method for producing an IEEE standard double precision
uniform [0,1) random variable.
It is simple, fast, and seems to pass tests of randomness very well.
Based on a method I developed for use in Matlab, the 32bit
floating point version was described in
"Toward a Universal Random Number Generator,''
Statistics and Probability Letters \bf 8, \rm No. 5, 1989
I can send my .ps or .pdf versions for those who have
trouble accessing those articles.

I now have the paper and translated the code to Fortran. With your
permission I will post it here for others to use. 

Back to top 


Dave Seaman science forum Guru
Joined: 24 Mar 2005
Posts: 527

Posted: Thu Nov 17, 2005 12:53 pm Post subject:
Re: Double precision random number generator in Fortran 77



On 17 Nov 2005 02:51:52 0800, os2_user@hotmail.com wrote:
Quote:  paul v birke wrote:
it compiles and runs under watcom
That's strange. Lahey doesn't like it and my Fortran book says it's an
error.

It's not strange. A standardconforming compiler is allowed to do anything it
likes when presented with a nonstandard program. One of the possibilities is
to accept it. This is called an "extension".
Quote:  The Fortran 77 version doesn't compile. There is an illegal data
statement for the variable mti which is in COMMON. It can be fixed by
having a block data statement. Has anyone else noticed this error?

Lots of Fortran 77 compilers accept this as an extension.

Dave Seaman
Judge Yohn's mistakes revealed in Mumia AbuJamal ruling.
<http://www.commoncouragepress.com/index.cfm?action=book&bookid=228> 

Back to top 


Duane Bozarth science forum beginner
Joined: 06 Jul 2005
Posts: 37

Posted: Thu Nov 17, 2005 3:49 pm Post subject:
Re: Double precision random number generator in Fortran 77



os2_user@hotmail.com wrote:
....top posting repaired...
Quote:  os2_user@hotmail.com wrote:
Hugo Pfoertner wrote:
os2_user@hotmail.com wrote:
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
Thanks.
Links to several implementations of the Mersenne Twister PRNG written in
Fortran can be found at
http://www.math.sci.hiroshimau.ac.jp/~mmat/MT/VERSIONS/FORTRAN/fortran.html
The Fortran 77 version doesn't compile. There is an illegal data
statement for the variable mti which is in COMMON. It can be fixed by
having a block data statement. Has anyone else noticed this error?
paul v birke wrote:
it compiles and runs under watcom
That's strange. Lahey doesn't like it and my Fortran book says it's an
error.

Do you have strict F77 conformance switch on or is it the default for
the Lahey compiler when presented a fixed source file? It is, as noted
elsewhere, a quite common extension but not, as you've noted, strict
F77. 

Back to top 


George Marsaglia science forum beginner
Joined: 24 May 2005
Posts: 21

Posted: Fri Nov 18, 2005 1:18 pm Post subject:
Re: Double precision random number generator in Fortran 77



<os2_user@hotmail.com> wrote in message
news:1132231159.103973.324440@z14g2000cwz.googlegroups.com...
Quote: 
George Marsaglia wrote:
os2_user@hotmail.com> wrote in message
news:1131947785.377811.265640@o13g2000cwo.googlegroups.com...
What is a good and free double precision random number generator in
Fortran 77? Is DUNI from Netlib ok? Is Ranlux available in double
precision and is it better? Are there better ones than these two
(longer period, pass all tests etc)?
The article
"The 64bit universal RNG", (2004)
{\it Statistics and Probability Letters}, {\bf 66}, no. 2, 183187,
(with Wai Wan Tsang)
describes a method for producing an IEEE standard double precision
uniform [0,1) random variable.
It is simple, fast, and seems to pass tests of randomness very well.
Based on a method I developed for use in Matlab, the 32bit
floating point version was described in
"Toward a Universal Random Number Generator,''
Statistics and Probability Letters \bf 8, \rm No. 5, 1989
I can send my .ps or .pdf versions for those who have
trouble accessing those articles.

I now have the paper and translated the code to Fortran. With your
permission I will post it here for others to use.

I have no objection.
You may want to make a change in the segment that fills the static table one
bit
at a time by means of two seeds, as the original had a slip in it,
correct: y=(8888*y)%65579; original: y=(8888*x)%65579;
Corrected or not, the method provides a satisfactory seed set, but that slip
in the original
makes it more difficult to calculate the number of distinct possible seed
sets.
And the fillU routine is just for the convenience of those who would be
content
with two integer seeds. For more general application, the array U[98]
should be
initialized with 98 random double precision seeds.
(My thanks to Raymond Toy for catching that slip.)
Here is the C version uni64( ), the 64bit double precision RNG
that generates the uniform variates directly, without the usual
floating of one or two integers.
#include <stdio.h>
static double U[98];
double uni64(void) {
const double r=9007199254740881.0/9007199254740992.;
const double d=362436069876.0/9007199254740992.0;
static double c=0.; static int i=97,j=33; double x;
x=U[i]U[j]; if(x<0.0) x=x+1.0; U[i]=x;
if(i==0) i=97; if(j==0) j=97;
c=cd; if(c<0.0) c=c+r;
x=xc; if(x<0.) return x+1.; return x; }
//A twoseed function for filling the static array U[98] one bit at a time
void fillU(int seed1,int seed2){
double s,t; int x,y,i,j; x=seed1; y=seed2;
for(i=1;i<98;i++){s=0.0;t=0.5;
for(j=1;j<54;j++)
{x=(6969*x)%65543;y=(8888*y)%65579;if(((x^y)&32)>0)s=s+t;t=.5*t;}
U[i]=s;} }
int main() {
double x; int i;
fillU( 123456789,987654321);
for(i=1;i<=10000000;i++) x=uni64();
for(i=1;i<=5;i++) printf("%18.0f \n",uni64()*9007199254740992.0);
}
/* Your output from the above run should look like this,
in which the uni64() doubles have been multiplied by 2^53
5534819329886631
7222984478804879
3591084909746267
6938004922860200
3518398318353033
*/
George Marsaglia 

Back to top 


Google


Back to top 



The time now is Wed Oct 18, 2017 12:00 am  All times are GMT

