in [Fortran]

Prev: pointer and allocatable arrays
Next: f95 to windows dll
From: Marina on 16 Nov 2009 16:58 Hi, I have a question regarding the subroutine RANDOM_NUMBER, does it generate a list of uniformly distributed numbers, between 0 and 1, and an average of 0.5? Which other intrinsic random number generating subroutines are available for Fortran 90, for other distributions? (I found that the function rand() doesn't work in my compiler, for example.) Thanks, Marina
From: steve on 16 Nov 2009 19:05 On Nov 16, 1:58 pm, Marina <levin.mar... (a)gmail.com> wrote:> > I have a question regarding the subroutine RANDOM_NUMBER, > does it generate a list of uniformly distributed numbers, between 0 > and 1, and an average of 0.5? The description for RANDOM_NUMBER is given in 13.14.85 of the Fortran 95 standard. It states Description. Returns one pseudorandom number or an array of pseudorandom numbers from the uniform distribution over the range 0 <= x < 1. Note, it says nothing about an average of 0.5. If you only draw 2 values from the distribution is highly unlikely that the average is 0.5. OTOH, if you draw hundred or thousands or millions of samples, then the average will be near 0.5. > Which other intrinsic random number generating subroutines are > available for Fortran 90, for other distributions? The Fortran standard requires that a comforming compiler must supply RANDOM_NUMBER. Vendors can choose to supply additional random number generators, so check your documentation. Note, there are numerous Fortran implementations of PRNG. Try searching on 'metcalf KISS' and 'ranlux' to name just two. There are others. As always, you should test whatever PRNG you choose to determine if it is adequate for your application. -- steve
From: frank on 16 Nov 2009 21:04 On Mon, 16 Nov 2009 16:05:14 -0800, steve wrote: >> I have a question regarding the subroutine RANDOM_NUMBER, does it >> generate a list of uniformly distributed numbers, between 0 and 1, and >> an average of 0.5? > > The description for RANDOM_NUMBER is given in 13.14.85 of the Fortran 95 > standard. It states > > Description. Returns one pseudorandom number or an array of > pseudorandom numbers from the uniform distribution over the range 0 > <= x < 1. > > Note, it says nothing about an average of 0.5. If you only draw 2 > values from the distribution is highly unlikely that the average is 0.5. > OTOH, if you draw hundred or thousands or millions of samples, then > the average will be near 0.5. Isn't there an asymmetry in the unit interval though as to which endpoint is included? So if there's N outcomes on one side of .5 there would be N +-1 on the other. -- frank "Guns: yes, they are harmful."
From: steve on 16 Nov 2009 21:48 On Nov 16, 6:04 pm, frank <fr... (a)example.invalid> wrote:> On Mon, 16 Nov 2009 16:05:14 -0800, steve wrote: > >> I have a question regarding the subroutine RANDOM_NUMBER, does it > >> generate a list of uniformly distributed numbers, between 0 and 1, and > >> an average of 0.5? > > > The description for RANDOM_NUMBER is given in 13.14.85 of the Fortran 95 > > standard. It states > > > Description. Returns one pseudorandom number or an array of > > pseudorandom numbers from the uniform distribution over the range 0 > > <= x < 1. > > > Note, it says nothing about an average of 0.5. If you only draw 2 > > values from the distribution is highly unlikely that the average is 0.5.. > > OTOH, if you draw hundred or thousands or millions of samples, then > > the average will be near 0.5. > > Isn't there an asymmetry in the unit interval though as to which endpoint > is included? So if there's N outcomes on one side of .5 there would be N > +-1 on the other. Can you restate your question without a little more detail? For example, for N=4, random_number in gfortran returns 0.998, 0.567, 0.966, 0.748. If I draw 10000 numbers and count the number in [0,0.5) and [0.5,1), the outcome is 4926 and 5074. If I draw 10000000 numbers, I get 4999679 and 50000321. If I reseed the rng with a different seed, these numbers change. -- steve
From: Arjen Markus on 17 Nov 2009 03:00
On 16 nov, 22:58, Marina <levin.mar... (a)gmail.com> wrote:> Hi, > > I have a question regarding the subroutine RANDOM_NUMBER, > does it generate a list of uniformly distributed numbers, between 0 > and 1, and an average of 0.5? > > Which other intrinsic random number generating subroutines are > available for Fortran 90, for other distributions? > (I found that the function rand() doesn't work in my compiler, for > example.) > > Thanks, > Marina Basically, from a uniform random number you can derive a random number with any distribution. It is a matter of using the inverse cumulative distribution function or one of several standard procedures. You may find the code and documentation by Alan Miller useful - a zip file miller_all.zip at http://groups.google.com/group/gg95. Regards, Arjen |