MODULE random_function_mod !------------------------------------------------------------------------------! ! Actual revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! \$Id: random_function.f90 4 2007-02-13 11:33:16Z raasch \$ ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.3 2003/10/29 09:06:57 raasch ! Former function changed to a module. ! ! Revision 1.1 1998/02/04 16:09:45 raasch ! Initial revision ! ! ! Description: ! ------------ ! Random number generator, produces numbers equally distributed in interval [0,1] ! This routine is taken from the "numerical recipies" !------------------------------------------------------------------------------! IMPLICIT NONE PRIVATE PUBLIC random_function, random_function_ini INTEGER, PUBLIC, SAVE :: random_iv(32), random_iy INTERFACE random_function_ini MODULE PROCEDURE random_function_ini END INTERFACE random_function_ini INTERFACE random_function MODULE PROCEDURE random_function END INTERFACE random_function CONTAINS SUBROUTINE random_function_ini IMPLICIT NONE random_iv = 0 random_iy = 0 END SUBROUTINE random_function_ini FUNCTION random_function( idum ) IMPLICIT NONE INTEGER :: ia, idum, im, iq, ir, ndiv, ntab REAL :: am, eps, random_function, ranf, rnmx PARAMETER ( ia=16807, im=2147483647, am=1.0/im, iq=127773, ir=2836, & ntab=32, ndiv=1+(im-1)/ntab, eps=1.2e-7, rnmx=1.0-eps ) INTEGER :: j, k IF ( idum .le. 0 .or. random_iy .eq. 0 ) THEN idum = max (-idum,1) DO j = ntab+8,1,-1 k = idum / iq idum = ia * ( idum - k * iq ) - ir * k IF ( idum .lt. 0 ) idum = idum + im IF ( j .le. ntab ) random_iv(j) = idum ENDDO random_iy = random_iv(1) ENDIF k = idum / iq idum = ia * ( idum - k * iq ) - ir * k IF ( idum .lt. 0 ) idum = idum + im j = 1 + random_iy / ndiv random_iy = random_iv(j) random_iv(j) = idum random_function = min ( am * random_iy , rnmx ) END FUNCTION random_function END MODULE random_function_mod