This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: [gfortran] Implement irand(), rand(), and srand() for G77 compatibility
On Sun, May 30, 2004 at 11:10:20PM +0100, Paul Brook wrote:
> On Sunday 30 May 2004 19:55, Steve Kargl wrote:
>
> > GFC_REAL_4 prefix(rand) (GFC_INTEGER_4 *i)
> > {
> > return (GFC_REAL_4) (prefix(irand)(i) - 1) / (GFC_REAL_4)(GFC_RAND_M1);
> > }
>
> This returns values in the range [0,1]
> We really need a reliable routine to convert from integer to real.
>
Nothing like a 3rd followup message. The original code is okay.
irand(i) returns a value in the range [1,GFC_RAND_M-1].
irand(i) - 1 is in the range [0,GFC_RAND_M-2]. So, the
division above is in the range [0,1).
--
Steve