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]

Fw: Random Number Generator]


----- Original Message ----- 
From: "Emil Block" <blime@his.com>
To: <blime@cox.net>
Sent: Thursday, June 05, 2003 10:32 AM
Subject: [Fwd: Random Number Generator]


> 
> 
--- Begin Message ---
Toone

You may recall responding to some questions I submitted on the GCC
random number generator
last year. As a result of that effort I modified rand_.c and
successfully reproduced the exact same
answers for a large simulation using the g77 and the Sun f77
compilers.

Attached is a modified rand_.c file that is an "improved/better" random
number generator for
g77.  Can you use the attached ? I'm not into patches.

Cheers
Emil Block
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of GNU Fortran libU77 library.

This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published
by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GNU Fortran is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with GNU Fortran; see the file COPYING.LIB.  If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.  */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if HAVE_STDLIB_H
#  include <stdlib.h>
#endif
#include "f2c.h"
#  define RAND_MAX 2147483647	/* from SunOS */


/* We could presumably do much better than the traditional libc
   version, though at least the glibc one is reasonable, it seems.
   For the sake of the innocent, I'm not sure we should really do
   this... */

/* Note this is per SunOS -- other s may have no arg. */

#ifdef KR_headers
double G77_rand_0 (flag)
  integer *flag;
#else
double G77_rand_0 (integer *flag)
#endif

{
  switch (*flag) {
  case 0:
    break;
  case 1:
    srandom (0);			/* changed by blime to do much better */
    break;
  default:
    initstate (*flag,4281826468,256);   /* produces same results as Sun F77 */
    srandom (*flag);
  }
  return (float) random () / RAND_MAX;
}

--- End Message ---

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