MODULE random_function_mod !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! PALM is free software: you can redistribute it and/or modify it under the terms ! of the GNU General Public License as published by the Free Software Foundation, ! either version 3 of the License, or (at your option) any later version. ! ! PALM 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 General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2012 Leibniz University Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: random_function.f90 1093 2013-02-02 12:58:49Z fricke $ ! ! 1092 2013-02-02 11:24:22Z raasch ! unused variables removed ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 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, 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