FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups 
 ProfileProfile   PreferencesPreferences   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Forum index » Science and Technology » Math » num-analysis
Double precision random number generator in Fortran 77
Post new topic   Reply to topic Page 1 of 2 [20 Posts] View previous topic :: View next topic
Goto page:  1, 2 Next
Author Message
os2_user@hotmail.com
science forum beginner


Joined: 14 Nov 2005
Posts: 9

PostPosted: Mon Nov 14, 2005 5:56 am    Post subject: Double precision random number generator in Fortran 77 Reply with 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.
Back to top
George Marsaglia
science forum beginner


Joined: 24 May 2005
Posts: 21

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

<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 64-bit universal RNG", (2004)
{\it Statistics and Probability Letters}, {\bf 66}, no. 2, 183-187,
(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 32-bit
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

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

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 Helbig---remove C
science forum addict


Joined: 06 May 2005
Posts: 88

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

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 double-precision 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

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

Phillip Helbig---remove 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 double-precision 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

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

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 double-precision 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
double-precision float mantissa.
Back to top
Hugo Pfoertner
science forum addict


Joined: 02 May 2005
Posts: 51

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

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.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/FORTRAN/fortran.html

Since the use of non-standard shift and bit-wise 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.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/c-lang.html
and link it to your Fortran code.

Hugo Pfoertner
Back to top
N. Shamsundar
science forum beginner


Joined: 10 Oct 2005
Posts: 40

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

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 double-precision 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
double-precision float mantissa.
What he said was equivalent to "take as many 24 bit scalar or vector

elements as are needed to fill your nn-bit mantissa". The "all" applied
to all the bits of the basic 24-bit 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

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

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.hiroshima-u.ac.jp/~m-mat/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

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

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.hiroshima-u.ac.jp/~m-mat/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

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

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.hiroshima-u.ac.jp/~m-mat/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

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

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 64-bit universal RNG", (2004)
{\it Statistics and Probability Letters}, {\bf 66}, no. 2, 183-187,
(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 32-bit
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

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

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 standard-conforming 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 Abu-Jamal 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

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

os2_user@hotmail.com wrote:
Quote:


....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.hiroshima-u.ac.jp/~m-mat/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

PostPosted: Fri Nov 18, 2005 1:18 pm    Post subject: Re: Double precision random number generator in Fortran 77 Reply with quote

<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 64-bit universal RNG", (2004)
{\it Statistics and Probability Letters}, {\bf 66}, no. 2, 183-187,
(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 32-bit
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 64-bit 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=c-d; if(c<0.0) c=c+r;
x=x-c; if(x<0.) return x+1.; return x; }

//A two-seed 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
Display posts from previous:   
Post new topic   Reply to topic Page 1 of 2 [20 Posts] Goto page:  1, 2 Next
View previous topic :: View next topic
The time now is Wed Oct 18, 2017 12:00 am | All times are GMT
Forum index » Science and Technology » Math » num-analysis
Jump to:  

Similar Topics
Topic Author Forum Replies Last Post
No new posts how to deduce a number validation algorithm? Tim_Mac Math 1 Fri Jul 21, 2006 10:43 am
No new posts Infinitesimal generator of a vector field Julien Santini Math 0 Fri Jul 21, 2006 8:01 am
No new posts a subset of natural number levine121323@yahoo.com Math 1 Fri Jul 21, 2006 6:17 am
No new posts reference books for formulaes in stochastic analysis and ... Michael11 Math 0 Thu Jul 20, 2006 12:38 am
No new posts Regarding Generator Matrices of MDS codes? jaco.versfeld@gmail.com Math 1 Wed Jul 19, 2006 1:10 pm

Copyright © 2004-2005 DeniX Solutions SRL
Other DeniX Solutions sites: Electronics forum |  Medicine forum |  Unix/Linux blog |  Unix/Linux documentation |  Unix/Linux forums  |  send newsletters
 


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.3886s ][ Queries: 16 (0.3594s) ][ GZIP on - Debug on ]