* Random Number Generator
@ 2002-08-02 9:48 Emil Block
2002-08-02 13:00 ` Toon Moene
0 siblings, 1 reply; 4+ messages in thread
From: Emil Block @ 2002-08-02 9:48 UTC (permalink / raw)
To: gcc-help
Does anyone know why a call to RAND with G77 returns a different value
than a call to RAND with F77 using the same seed? The computer is a SUN
Sparc with OS 2.7. The same code is compiled in one case with G77 and in
the other case with F77.
G77 rand (iseed) returns 0.563463211
F77 rand (iseed) returns 0.843506
where iseed = 1375.
Emil Block
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Random Number Generator
2002-08-02 9:48 Random Number Generator Emil Block
@ 2002-08-02 13:00 ` Toon Moene
2002-08-02 14:37 ` Emil Block
0 siblings, 1 reply; 4+ messages in thread
From: Toon Moene @ 2002-08-02 13:00 UTC (permalink / raw)
To: Emil Block; +Cc: gcc-help
Emil Block wrote:
> Does anyone know why a call to RAND with G77 returns a different value
> than a call to RAND with F77 using the same seed? The computer is a SUN
> Sparc with OS 2.7. The same code is compiled in one case with G77 and in
> the other case with F77.
>
> G77 rand (iseed) returns 0.563463211
> F77 rand (iseed) returns 0.843506
>
> where iseed = 1375.
It would help if you could figure out how the Sun Fortran run time library
does this.
G77's actually does:
srand(iseed);
return rand();
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Random Number Generator
2002-08-02 13:00 ` Toon Moene
@ 2002-08-02 14:37 ` Emil Block
2002-08-06 9:02 ` Toon Moene
0 siblings, 1 reply; 4+ messages in thread
From: Emil Block @ 2002-08-02 14:37 UTC (permalink / raw)
To: Toon Moene; +Cc: gcc-help
Toon Moene wrote:
>
> Emil Block wrote:
>
> > Does anyone know why a call to RAND with G77 returns a different value
> > than a call to RAND with F77 using the same seed? The computer is a SUN
> > Sparc with OS 2.7. The same code is compiled in one case with G77 and in
> > the other case with F77.
> >
> > G77 rand (iseed) returns 0.563463211
> > F77 rand (iseed) returns 0.843506
> >
> > where iseed = 1375.
>
> It would help if you could figure out how the Sun Fortran run time library
> does this.
>
> G77's actually does:
>
> srand(iseed);
> return rand();
>
> --
> Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
> Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
> Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
> Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
Toon
Here's what the documentation contains:
Sun WorkShop Compilers FORTRAN 77 5.0
rand, drand, irand: Return Random Values
rand returns real values in the range 0.0 through 1.0.
drand returns double precision values in the range 0.0 through 1.0.
irand returns positive integers in the range 0 through 2147483647.
These functions use random(3) to generate sequences of random numbers.
The three functions share the same 256 byte state array. The only advantage
of these functions is that they are widely available on UNIX systems. For
better random number generators, compare lcrans, addrans, and shufrans. See
also random(3), and the Numerical Computation Guide
i = irand( k )
r = rand( k )
d = drand( k )
k INTEGER*4 Input
k=0: Get next random number in the sequence
k=1: Restart sequence, return first number
k>0: Use as a seed for new sequence, return first number
rand REAL*4 Output
drand REAL*8 Output
irand INTEGER*4 Output
No mention of srand but the funtion exists as well as srandom.
Is G77 (rand_.c and srand_.c) doing an additional draw?
Emil Block
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Random Number Generator
2002-08-02 14:37 ` Emil Block
@ 2002-08-06 9:02 ` Toon Moene
0 siblings, 0 replies; 4+ messages in thread
From: Toon Moene @ 2002-08-06 9:02 UTC (permalink / raw)
To: Emil Block; +Cc: gcc-help
Emil Block wrote:
> Toon Moene wrote:
>>G77's actually does:
>>
>>srand(iseed);
>>return rand();
> i = irand( k )
> r = rand( k )
> d = drand( k )
>
> k INTEGER*4 Input
> k=0: Get next random number in the sequence
> k=1: Restart sequence, return first number
> k>0: Use as a seed for new sequence, return first number
>
> rand REAL*4 Output
> drand REAL*8 Output
> irand INTEGER*4 Output
>
> No mention of srand but the funtion exists as well as srandom.
>
> Is G77 (rand_.c and srand_.c) doing an additional draw?
Sorry for answering this so late ...
From your description of whan Sun does, I'd say they do the same. They
must use *some* function to restart the sequence, and one would hope
that it were srand.
However, given the current evidence, it's hard to say. Perhaps you
could ask Sun ?
--
Toon Moene - mailto:toon@moene.indiv.nluug.nl - phoneto: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Maintainer, GNU Fortran 77: http://gcc.gnu.org/onlinedocs/g77_news.html
Join GNU Fortran 95: http://g95.sourceforge.net/ (under construction)
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-08-06 16:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-02 9:48 Random Number Generator Emil Block
2002-08-02 13:00 ` Toon Moene
2002-08-02 14:37 ` Emil Block
2002-08-06 9:02 ` Toon Moene
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).