This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: GNU Fortran inquiry



Subject forgotten, so once again for gcc.gnu.org.

>
> >> That way, the sequence
> >>
> >>    Call srand(seed_value)
> >>
> >>    do j= 1,10
> >>      Write(*,*) rand()
> >>    enddo
> >>
> >> will give you ten "random numbers" for the seed seed_value.
>
> >The RAND function is defined as RAND(Flag), and it returns a pseudo-random
> >number in <0,1>. If Flag is 0, the next number in sequence is returned; if
> >Flag is 1, the generator is restarted by calling `srand(0)'; if Flag has any
> >other value, it is used as a new seed with srand.
>
> >See the GNU Fortran manual for details:
> >http://gcc.gnu.org/onlinedocs/g77_12.html#SEC314
>
> >Both the RAND and SRAND intrinsics are described in this manual.
>
>
> Well, in case of using _non_ standard function, you had to more carefully
> check, how it is implemented in other Unix dialects native compilers.
>
> I.e.: On Digital UNIX4 we read via "man rand"
>
>  -------
>
> NAME
>
>   rand, rand_r, srand - Generates pseudorandom numbers
>
> LIBRARY
>
>   Standard C Library (libc.so, libc.a),
>   Berkeley Compatibility Library (libbsd.a)
>
> SYNOPSIS
>
>   #include <stdlib.h>
>   int rand (void);
>
>   int rand_r(
>           unsigned int *seedptr);
>
>   void srand(
>           unsigned int seed);
>
>   The following function does not conform to current standards and is sup-
>   ported only for backward compatibility:
>
>   int rand_r(
>           unsigned int *seedptr,
>           int *randval);
>
> STANDARDS
>
>   Interfaces documented on this reference page conform to industry standards
>   as follows:
>
>   rand_r():  POSIX.1c
>
>   rand(), srand():  XPG4, XPG4-UNIX
>
>   Refer to the standards(5) reference page for more information about indus-
>   try standards and associated tags.
>
> PARAMETERS
>
>   seed      Specifies an initial seed value.
>
>   seedptr   Points to a seed value, updated at each call.
>
>   randval   Points to a place to store the random number.
>
>  ...
>
>   The following functions define the semantics of the rand() and srand()
>   functions, and are included here to facilitate porting applications from
>   different implementations:
>
>        static unsigned int next = 1;
>        int myrand(void)
>        {
>                next = next * 1103515245 + 12345;
>                return (  (next >>16) & RAND_MAX);
>        }
>        void mysrand (unsigned int seed)
>        {
>        next = seed
>        }
>
>  ----------
>
> Note, that this page states, that srand/rand is implemented, as i
> indicate it. I.e. rand has no argument.
>
> Peter Schorsch
>
> P.S.: Because it's non standard Fortran 77, one should supply an (good)
>       own implementation with the source ...
>
>
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]